diff options
author | François Dumont <fdumont@gcc.gnu.org> | 2022-08-14 17:11:02 +0200 |
---|---|---|
committer | François Dumont <fdumont@gcc.gnu.org> | 2022-08-31 21:22:09 +0200 |
commit | 5f932c9f93c45440a7baf7d9059d3b33a0f2d2db (patch) | |
tree | 05a4692a398655bde18565bb51f1ca6b08915ae7 /libstdc++-v3 | |
parent | f956cadc292aec42ceeba1e4835ad795c9aab5c2 (diff) | |
download | gcc-5f932c9f93c45440a7baf7d9059d3b33a0f2d2db.zip gcc-5f932c9f93c45440a7baf7d9059d3b33a0f2d2db.tar.gz gcc-5f932c9f93c45440a7baf7d9059d3b33a0f2d2db.tar.bz2 |
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..
Diffstat (limited to 'libstdc++-v3')
8 files changed, 44 insertions, 16 deletions
diff --git a/libstdc++-v3/include/debug/debug.h b/libstdc++-v3/include/debug/debug.h index 28e250f..f423376 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 a4482db..c16751c 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 cfe18e0..3cf8512 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 32f3449..ba77f01 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 d27e824..70b522f 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 5c0b3af..dddf51c 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 9e0d665..a023d9e 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 eda7321..747b23a 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 ); |