public inbox for libstdc++-cvs@sourceware.org help / color / mirror / Atom feed
From: "Franथईois Dumont" <fdumont@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org Subject: [gcc r13-2318] libstdc++: [_GLIBCXX_DEBUG] Review nullptr assertion diagnostics Date: Wed, 31 Aug 2022 19:22:40 +0000 (GMT) [thread overview] Message-ID: <20220831192240.2C2E03851143@sourceware.org> (raw) https://gcc.gnu.org/g:5f932c9f93c45440a7baf7d9059d3b33a0f2d2db commit r13-2318-g5f932c9f93c45440a7baf7d9059d3b33a0f2d2db Author: François Dumont <fdumont@gcc.gnu.org> Date: Sun Aug 14 17:11:02 2022 +0200 libstdc++: [_GLIBCXX_DEBUG] Review nullptr assertion diagnostics Review null string checks to show: _String != nullptr rather than: _String != 0 libstdc++-v3/ChangeLog: * include/debug/debug.h: Use nullptr rather than '0' in checks in post-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/nonnull.cc: Likewise. * testsuite/21_strings/basic_string/operations/ends_with/wchar_t.cc: Likewise. * testsuite/21_strings/basic_string/operations/starts_with/wchar_t.cc: Likewise. * testsuite/21_strings/basic_string/operations/starts_with/nonnull.cc: Likewise. * testsuite/21_strings/basic_string/operations/starts_with/char.cc: Likewise.. Diff: --- libstdc++-v3/include/debug/debug.h | 11 ++++++++-- libstdc++-v3/include/debug/string | 25 ++++++++++++++++++++-- .../basic_string/operations/ends_with/char.cc | 4 ++-- .../basic_string/operations/ends_with/nonnull.cc | 4 ++-- .../basic_string/operations/ends_with/wchar_t.cc | 4 ++-- .../basic_string/operations/starts_with/char.cc | 4 ++-- .../basic_string/operations/starts_with/nonnull.cc | 4 ++-- .../basic_string/operations/starts_with/wchar_t.cc | 4 ++-- 8 files changed, 44 insertions(+), 16 deletions(-) diff --git a/libstdc++-v3/include/debug/debug.h b/libstdc++-v3/include/debug/debug.h index 28e250f0c50..f4233760426 100644 --- a/libstdc++-v3/include/debug/debug.h +++ b/libstdc++-v3/include/debug/debug.h @@ -118,10 +118,17 @@ namespace __gnu_debug __glibcxx_check_heap(_First,_Last) # define __glibcxx_requires_heap_pred(_First,_Last,_Pred) \ __glibcxx_check_heap_pred(_First,_Last,_Pred) -# define __glibcxx_requires_string(_String) \ +# if __cplusplus < 201103L +# define __glibcxx_requires_string(_String) \ _GLIBCXX_DEBUG_PEDASSERT(_String != 0) -# define __glibcxx_requires_string_len(_String,_Len) \ +# define __glibcxx_requires_string_len(_String,_Len) \ _GLIBCXX_DEBUG_PEDASSERT(_String != 0 || _Len == 0) +# else +# define __glibcxx_requires_string(_String) \ + _GLIBCXX_DEBUG_PEDASSERT(_String != nullptr) +# define __glibcxx_requires_string_len(_String,_Len) \ + _GLIBCXX_DEBUG_PEDASSERT(_String != nullptr || _Len == 0) +# endif # define __glibcxx_requires_irreflexive(_First,_Last) \ __glibcxx_check_irreflexive(_First,_Last) # define __glibcxx_requires_irreflexive2(_First,_Last) \ diff --git a/libstdc++-v3/include/debug/string b/libstdc++-v3/include/debug/string index a4482db4af5..c16751c891b 100644 --- a/libstdc++-v3/include/debug/string +++ b/libstdc++-v3/include/debug/string @@ -50,14 +50,25 @@ #endif #ifdef _GLIBCXX_DEBUG_PEDANTIC -# define __glibcxx_check_string(_String) \ +# if __cplusplus < 201103L +# define __glibcxx_check_string(_String) \ _GLIBCXX_DEBUG_VERIFY_STR_COND_AT(_String != 0, \ __FILE__, __LINE__, \ __PRETTY_FUNCTION__); -# define __glibcxx_check_string_len(_String,_Len) \ +# define __glibcxx_check_string_len(_String,_Len) \ _GLIBCXX_DEBUG_VERIFY_STR_COND_AT(_String != 0 || _Len == 0, \ __FILE__, __LINE__, \ __PRETTY_FUNCTION__); +# else +# define __glibcxx_check_string(_String) \ + _GLIBCXX_DEBUG_VERIFY_STR_COND_AT(_String != nullptr, \ + __FILE__, __LINE__, \ + __PRETTY_FUNCTION__); +# define __glibcxx_check_string_len(_String,_Len) \ + _GLIBCXX_DEBUG_VERIFY_STR_COND_AT(_String != nullptr || _Len == 0, \ + __FILE__, __LINE__, \ + __PRETTY_FUNCTION__); +# endif #else # define __glibcxx_check_string(_String) # define __glibcxx_check_string_len(_String,_Len) @@ -75,8 +86,13 @@ namespace __gnu_debug const char* __function __attribute__((__unused__))) { #ifdef _GLIBCXX_DEBUG_PEDANTIC +# if __cplusplus < 201103L _GLIBCXX_DEBUG_VERIFY_STR_COND_AT(__s != 0 || __n == 0, __file, __line, __function); +# else + _GLIBCXX_DEBUG_VERIFY_STR_COND_AT(__s != nullptr || __n == 0, + __file, __line, __function); +# endif #endif return __s; } @@ -90,8 +106,13 @@ namespace __gnu_debug const char* __function __attribute__((__unused__))) { #ifdef _GLIBCXX_DEBUG_PEDANTIC +# if __cplusplus < 201103L _GLIBCXX_DEBUG_VERIFY_STR_COND_AT(__s != 0, __file, __line, __function); +# else + _GLIBCXX_DEBUG_VERIFY_STR_COND_AT(__s != nullptr, + __file, __line, __function); +# endif #endif return __s; } diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/operations/ends_with/char.cc b/libstdc++-v3/testsuite/21_strings/basic_string/operations/ends_with/char.cc index cfe18e0186c..3cf85121e36 100644 --- a/libstdc++-v3/testsuite/21_strings/basic_string/operations/ends_with/char.cc +++ b/libstdc++-v3/testsuite/21_strings/basic_string/operations/ends_with/char.cc @@ -20,7 +20,7 @@ // basic_string ends_with -#include <string> +#include <testsuite_string.h> #include <testsuite_hooks.h> void @@ -31,7 +31,7 @@ test01() const char cstr_suf2[] = ".rgb"; const std::string_view sv_suf2(".rgb"); - const std::string s_test("slugs/slimy.jpg"); + const __gnu_test::string s_test("slugs/slimy.jpg"); const auto cstr_in_slugs = s_test.ends_with(cstr_suf); VERIFY( cstr_in_slugs ); diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/operations/ends_with/nonnull.cc b/libstdc++-v3/testsuite/21_strings/basic_string/operations/ends_with/nonnull.cc index 32f3449b4e9..ba77f0124d0 100644 --- a/libstdc++-v3/testsuite/21_strings/basic_string/operations/ends_with/nonnull.cc +++ b/libstdc++-v3/testsuite/21_strings/basic_string/operations/ends_with/nonnull.cc @@ -1,10 +1,10 @@ // { dg-options "-std=gnu++20 -Wnonnull -O0 -Wno-unused-result" } // { dg-do compile { target c++20 } } -#include <string> +#include <testsuite_string.h> void -test01(const std::string& s) +test01(const __gnu_test::string& s) { s.ends_with((const char*)nullptr); // { dg-warning "\\\[-Wnonnull" } s.ends_with((char*)nullptr); // { dg-warning "\\\[-Wnonnull" } diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/operations/ends_with/wchar_t.cc b/libstdc++-v3/testsuite/21_strings/basic_string/operations/ends_with/wchar_t.cc index d27e8246fb8..70b522ff69e 100644 --- a/libstdc++-v3/testsuite/21_strings/basic_string/operations/ends_with/wchar_t.cc +++ b/libstdc++-v3/testsuite/21_strings/basic_string/operations/ends_with/wchar_t.cc @@ -20,7 +20,7 @@ // basic_string ends_with -#include <string> +#include <testsuite_string.h> #include <testsuite_hooks.h> void @@ -31,7 +31,7 @@ test01() const wchar_t cstr_suf2[] = L".rgb"; const std::wstring_view sv_suf2(L".rgb"); - const std::wstring s_test(L"slugs/slimy.jpg"); + const __gnu_test::wstring s_test(L"slugs/slimy.jpg"); const auto cstr_in_slugs = s_test.ends_with(cstr_suf); VERIFY( cstr_in_slugs ); diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/operations/starts_with/char.cc b/libstdc++-v3/testsuite/21_strings/basic_string/operations/starts_with/char.cc index 5c0b3afc0b6..dddf51cee16 100644 --- a/libstdc++-v3/testsuite/21_strings/basic_string/operations/starts_with/char.cc +++ b/libstdc++-v3/testsuite/21_strings/basic_string/operations/starts_with/char.cc @@ -20,7 +20,7 @@ // basic_string begins_with -#include <string> +#include <testsuite_string.h> #include <testsuite_hooks.h> void @@ -31,7 +31,7 @@ test01() const char cstr_dir2[] = "worms/"; const std::string_view sv_dir2("worms/"); - const std::string s_test("slugs/slimy.jpg"); + const __gnu_test::string s_test("slugs/slimy.jpg"); const auto cstr_in_slugs = s_test.starts_with(cstr_dir); VERIFY( cstr_in_slugs ); diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/operations/starts_with/nonnull.cc b/libstdc++-v3/testsuite/21_strings/basic_string/operations/starts_with/nonnull.cc index 9e0d6659e66..a023d9ec227 100644 --- a/libstdc++-v3/testsuite/21_strings/basic_string/operations/starts_with/nonnull.cc +++ b/libstdc++-v3/testsuite/21_strings/basic_string/operations/starts_with/nonnull.cc @@ -1,10 +1,10 @@ // { dg-options "-std=gnu++20 -Wnonnull -O0 -Wno-unused-result" } // { dg-do compile { target c++20 } } -#include <string> +#include <testsuite_string.h> void -test01(const std::string& s) +test01(const __gnu_test::string& s) { s.starts_with((const char*)nullptr); // { dg-warning "\\\[-Wnonnull" } s.starts_with((char*)nullptr); // { dg-warning "\\\[-Wnonnull" } diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/operations/starts_with/wchar_t.cc b/libstdc++-v3/testsuite/21_strings/basic_string/operations/starts_with/wchar_t.cc index eda73212ea0..747b23ae5c2 100644 --- a/libstdc++-v3/testsuite/21_strings/basic_string/operations/starts_with/wchar_t.cc +++ b/libstdc++-v3/testsuite/21_strings/basic_string/operations/starts_with/wchar_t.cc @@ -20,7 +20,7 @@ // basic_string begins_with -#include <string> +#include <testsuite_string.h> #include <testsuite_hooks.h> void @@ -31,7 +31,7 @@ test01() const wchar_t cstr_dir2[] = L"worms/"; const std::wstring_view sv_dir2(L"worms/"); - const std::wstring s_test(L"slugs/slimy.jpg"); + const __gnu_test::wstring s_test(L"slugs/slimy.jpg"); const auto cstr_in_slugs = s_test.starts_with(cstr_dir); VERIFY( cstr_in_slugs );
reply other threads:[~2022-08-31 19:22 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20220831192240.2C2E03851143@sourceware.org \ --to=fdumont@gcc.gnu.org \ --cc=gcc-cvs@gcc.gnu.org \ --cc=libstdc++-cvs@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: linkBe 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).