From: "François Dumont" <frs.dumont@gmail.com>
To: "libstdc++@gcc.gnu.org" <libstdc++@gcc.gnu.org>
Subject: Re: [PATCH][_GLIBCXX_DEBUG] Add basic_string::starts_with/ends_with checks
Date: Thu, 25 Aug 2022 18:11:26 +0200 [thread overview]
Message-ID: <10daf589-f064-5d82-3093-9efe3d5af910@gmail.com> (raw)
In-Reply-To: <0ec115b4-917a-403e-88fe-6a9360659bd8@gmail.com>
[-- Attachment #1: Type: text/plain, Size: 2798 bytes --]
I spent more time on this.
Is there some discussion in the C++ Standard Committee to do something
like what I've done ? I guess adding nullptr_t overloads for all the
methods taking pointer is not an option, is it ?
Note that compilation fails but despite the dg-do xfail the test ends up
FAIL and not XFAIL. Is this the correct syntax:
// { dg-do compile { target c++2a xfail *-*-* } }
?
Thanks,
François
On 15/08/22 22:26, François Dumont wrote:
> With the patch !
>
> On 14/08/22 17:32, François Dumont wrote:
>> I think we can add those checks.
>>
>> Note that I wonder if it was needed as in basic_string_view I see
>> usages of __attribute__((__nonnull__)). But running the test I saw no
>> impact even after I try to apply this attribute to the
>> starts_with/ends_with methods themselves.
>>
>> Also note that several checks like the ones I am adding here are
>> XFAILS when using 'make check' because of the segfault rather than on
>> a proper debug checks. Would you prefer to add dg-require-debug-mode
>> to those ?
>>
>> libstdc++: [_GLIBCXX_DEBUG] Add
>> basic_string::starts_with/ends_with checks
>>
>> Add simple checks on C string parameters which should not be null.
>>
>> Review null string checks to show:
>> _String != nullptr
>>
>> rather than:
>> _String != 0
>>
>> libstdc++-v3/ChangeLog:
>>
>> * include/bits/basic_string.h (starts_with, ends_with):
>> Add __glibcxx_check_string.
>> * include/bits/cow_string.h (starts_with, ends_with):
>> Likewise.
>> * include/debug/debug.h: Use nullptr rather than '0' in
>> checks in C++11.
>> * include/debug/string: Likewise.
>> *
>> testsuite/21_strings/basic_string/operations/ends_with/char.cc: Use
>> __gnu_test::string.
>> *
>> testsuite/21_strings/basic_string/operations/ends_with/wchar_t.cc:
>> Use __gnu_test::wstring.
>> *
>> testsuite/21_strings/basic_string/operations/starts_with/wchar_t.cc:
>> Use __gnu_test::wstring.
>> *
>> testsuite/21_strings/basic_string/operations/starts_with/char.cc: Use
>> __gnu_test::string.
>> *
>> testsuite/21_strings/basic_string/operations/ends_with/char_neg.cc:
>> New test.
>> *
>> testsuite/21_strings/basic_string/operations/ends_with/wchar_t_neg.cc:
>> New test.
>> *
>> testsuite/21_strings/basic_string/operations/starts_with/char_neg.cc:
>> New test.
>> *
>> testsuite/21_strings/basic_string/operations/starts_with/wchar_t_neg.cc:
>> New test.
>>
>> Tested under linux normal and debug modes.
>>
>> François
>>
>>
[-- Attachment #2: nullptr_t.patch --]
[-- Type: text/x-patch, Size: 4724 bytes --]
diff --git a/libstdc++-v3/include/bits/basic_string.h b/libstdc++-v3/include/bits/basic_string.h
index d06330e6c48..1be42e415f5 100644
--- a/libstdc++-v3/include/bits/basic_string.h
+++ b/libstdc++-v3/include/bits/basic_string.h
@@ -3407,6 +3407,9 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
return __sv_type(this->data(), this->size()).starts_with(__x);
}
+ bool
+ starts_with(nullptr_t) const noexcept = delete;
+
constexpr bool
ends_with(basic_string_view<_CharT, _Traits> __x) const noexcept
{ return __sv_type(this->data(), this->size()).ends_with(__x); }
@@ -3421,6 +3424,9 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
__glibcxx_requires_string(__x);
return __sv_type(this->data(), this->size()).ends_with(__x);
}
+
+ bool
+ ends_with(nullptr_t) const noexcept = delete;
#endif // C++20
#if __cplusplus > 202002L
diff --git a/libstdc++-v3/include/bits/cow_string.h b/libstdc++-v3/include/bits/cow_string.h
index 59b36a1006a..f8f0959554d 100644
--- a/libstdc++-v3/include/bits/cow_string.h
+++ b/libstdc++-v3/include/bits/cow_string.h
@@ -3019,6 +3019,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
return __sv_type(this->data(), this->size()).starts_with(__x);
}
+ bool
+ starts_with(nullptr_t) const noexcept = delete;
+
bool
ends_with(basic_string_view<_CharT, _Traits> __x) const noexcept
{ return __sv_type(this->data(), this->size()).ends_with(__x); }
@@ -3033,6 +3036,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
__glibcxx_requires_string(__x);
return __sv_type(this->data(), this->size()).ends_with(__x);
}
+
+ bool
+ ends_with(nullptr_t) const noexcept = delete;
#endif // C++20
#if __cplusplus > 202011L
diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/operations/ends_with/char_neg.cc b/libstdc++-v3/testsuite/21_strings/basic_string/operations/ends_with/char_neg.cc
index 7a7b8dd077d..273e9a6a564 100644
--- a/libstdc++-v3/testsuite/21_strings/basic_string/operations/ends_with/char_neg.cc
+++ b/libstdc++-v3/testsuite/21_strings/basic_string/operations/ends_with/char_neg.cc
@@ -15,10 +15,8 @@
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
//
-// { dg-options "-std=gnu++2a -O0" }
-// { dg-do run { target c++2a xfail *-*-* } }
-
-#define _GLIBCXX_DEBUG_PEDANTIC
+// { dg-options "-std=gnu++2a" }
+// { dg-do compile { target c++2a xfail *-*-* } }
#include <testsuite_string.h>
diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/operations/ends_with/wchar_t_neg.cc b/libstdc++-v3/testsuite/21_strings/basic_string/operations/ends_with/wchar_t_neg.cc
index a6881bf406b..07588ea2bf7 100644
--- a/libstdc++-v3/testsuite/21_strings/basic_string/operations/ends_with/wchar_t_neg.cc
+++ b/libstdc++-v3/testsuite/21_strings/basic_string/operations/ends_with/wchar_t_neg.cc
@@ -15,10 +15,8 @@
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
//
-// { dg-options "-std=gnu++2a -O0" }
-// { dg-do run { target c++2a xfail *-*-* } }
-
-#define _GLIBCXX_DEBUG_PEDANTIC
+// { dg-options "-std=gnu++2a" }
+// { dg-do compile { target c++2a xfail *-*-* } }
#include <testsuite_string.h>
diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/operations/starts_with/char_neg.cc b/libstdc++-v3/testsuite/21_strings/basic_string/operations/starts_with/char_neg.cc
index f357aef2289..9b6b0d2ddda 100644
--- a/libstdc++-v3/testsuite/21_strings/basic_string/operations/starts_with/char_neg.cc
+++ b/libstdc++-v3/testsuite/21_strings/basic_string/operations/starts_with/char_neg.cc
@@ -15,10 +15,8 @@
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
//
-// { dg-options "-std=gnu++2a -O0" }
-// { dg-do run { target c++2a xfail *-*-* } }
-
-#define _GLIBCXX_DEBUG_PEDANTIC
+// { dg-options "-std=gnu++2a" }
+// { dg-do compile { target c++2a xfail *-*-* } }
#include <testsuite_string.h>
diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/operations/starts_with/wchar_t_neg.cc b/libstdc++-v3/testsuite/21_strings/basic_string/operations/starts_with/wchar_t_neg.cc
index 90065a459b6..1ea10d1ab39 100644
--- a/libstdc++-v3/testsuite/21_strings/basic_string/operations/starts_with/wchar_t_neg.cc
+++ b/libstdc++-v3/testsuite/21_strings/basic_string/operations/starts_with/wchar_t_neg.cc
@@ -15,10 +15,8 @@
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
//
-// { dg-options "-std=gnu++2a -O0" }
-// { dg-do run { target c++2a xfail *-*-* } }
-
-#define _GLIBCXX_DEBUG_PEDANTIC
+// { dg-options "-std=gnu++2a" }
+// { dg-do compile { target c++2a xfail *-*-* } }
#include <testsuite_string.h>
next prev parent reply other threads:[~2022-08-25 16:11 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-14 15:32 François Dumont
2022-08-15 20:26 ` François Dumont
2022-08-25 16:11 ` François Dumont [this message]
2022-08-26 9:33 ` Jonathan Wakely
2022-08-26 9:31 ` Jonathan Wakely
2022-08-31 4:38 ` [PATCH][_GLIBCXX_DEBUG] Review null string assertions (was: Add basic_string::starts_with/ends_with checks) François Dumont
2022-08-31 9:25 ` Jonathan Wakely
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=10daf589-f064-5d82-3093-9efe3d5af910@gmail.com \
--to=frs.dumont@gmail.com \
--cc=libstdc++@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).