]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libstdc++: [_GLIBCXX_DEBUG] Review nullptr assertion diagnostics
authorFrançois Dumont <fdumont@gcc.gnu.org>
Sun, 14 Aug 2022 15:11:02 +0000 (17:11 +0200)
committerFrançois Dumont <fdumont@gcc.gnu.org>
Wed, 31 Aug 2022 19:22:09 +0000 (21:22 +0200)
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..

libstdc++-v3/include/debug/debug.h
libstdc++-v3/include/debug/string
libstdc++-v3/testsuite/21_strings/basic_string/operations/ends_with/char.cc
libstdc++-v3/testsuite/21_strings/basic_string/operations/ends_with/nonnull.cc
libstdc++-v3/testsuite/21_strings/basic_string/operations/ends_with/wchar_t.cc
libstdc++-v3/testsuite/21_strings/basic_string/operations/starts_with/char.cc
libstdc++-v3/testsuite/21_strings/basic_string/operations/starts_with/nonnull.cc
libstdc++-v3/testsuite/21_strings/basic_string/operations/starts_with/wchar_t.cc

index 28e250f0c509da0dffb7ae44b72f0a8027d49faa..f4233760426e071714436ac818a70d547b124b7d 100644 (file)
@@ -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) \
index a4482db4af587f97c41003bc81696665e4c213ca..c16751c891b9eec9b9bed15a25c5149d1d2a8264 100644 (file)
 #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;
     }
index cfe18e0186cdcf124189e1c42758903f54995bf8..3cf85121e360f4d6cfc925cc5bd25cac0298a243 100644 (file)
@@ -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 );
index 32f3449b4e9a9f4eda1250114671753e8d9a31b1..ba77f0124d06ef8b370435df5d887a4c728fc206 100644 (file)
@@ -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" }
index d27e8246fb8769ccaa692096af5344e4f6ded597..70b522ff69e86ca2786b37c02cd02f74458ece76 100644 (file)
@@ -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 );
index 5c0b3afc0b6a68598cb8f36843ce87ffe8f40d71..dddf51cee167c855960e5ec020403ab0dfb3e839 100644 (file)
@@ -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 );
index 9e0d6659e66432e0be8d7f1ccee47efa197cb60a..a023d9ec227082e8bccc31b7e6fdc607d7623c12 100644 (file)
@@ -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" }
index eda73212ea0c0a9af16546061e589733453a5550..747b23ae5c2c61eca4ce73a6348aa31a527dd21b 100644 (file)
@@ -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 );