]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libstdc++: Support P2510R3 "Formatting pointers" as a DR for C++20
authorJonathan Wakely <jwakely@redhat.com>
Thu, 11 Jul 2024 23:30:24 +0000 (00:30 +0100)
committerJonathan Wakely <redi@gcc.gnu.org>
Wed, 31 Jul 2024 16:07:10 +0000 (17:07 +0100)
We already enable this for -std=gnu++20 but we can do it for -std=c++20
too. Both libc++ and MSVC also treat this change as a DR for C++20.

Now that the previous change to the value of __cpp_lib_format is
supported, we can finally update it to 202304 to indicate support for
this feature too.

libstdc++-v3/ChangeLog:

* include/bits/version.def (format): Update value for P2510R3.
* include/bits/version.h: Regenerate.
* include/std/format (_GLIBCXX_P2518R3): Remove misspelled macro
and check __glibcxx_format instead.
* testsuite/std/format/functions/format.cc: Check value of the
__cpp_lib_format macro for formatting pointers support.
* testsuite/std/format/parse_ctx.cc: Likewise.

libstdc++-v3/include/bits/version.def
libstdc++-v3/include/bits/version.h
libstdc++-v3/include/std/format
libstdc++-v3/testsuite/std/format/functions/format.cc
libstdc++-v3/testsuite/std/format/parse_ctx.cc

index 74947301760792aa68c46c4844f1c38608f9aa17..1acc9cd5cb9aeb92777d2fee8af27ba479ae91b7 100644 (file)
@@ -1162,12 +1162,11 @@ ftms = {
 
 ftms = {
   name = format;
-  // 202304 P2510R3 Formatting pointers
   // 202305 P2757R3 Type checking format args
   // 202306 P2637R3 Member visit
   // 202311 P2918R2 Runtime format strings II
   // values = {
-    // v = 202304;
+    // v = 202305;
     // cxxmin = 26;
     // hosted = yes;
   // };
@@ -1175,8 +1174,9 @@ ftms = {
   // 202106 std::format improvements.
   // 202110 Fixing locale handling in chrono formatters, generator-like types.
   // 202207 Encodings in localized formatting of chrono, basic-format-string.
+  // 202304 P2510R3 Formatting pointers
   values = {
-    v = 202207;
+    v = 202304;
     cxxmin = 20;
     hosted = yes;
   };
index 9f8673395dabfc3de65d29a227ce1847fe681681..5cd77770e213e24615c0ff8c268e53113d873c6d 100644 (file)
 
 #if !defined(__cpp_lib_format)
 # if (__cplusplus >= 202002L) && _GLIBCXX_HOSTED
-#  define __glibcxx_format 202207L
+#  define __glibcxx_format 202304L
 #  if defined(__glibcxx_want_all) || defined(__glibcxx_want_format)
-#   define __cpp_lib_format 202207L
+#   define __cpp_lib_format 202304L
 #  endif
 # endif
 #endif /* !defined(__cpp_lib_format) && defined(__glibcxx_want_format) */
index fe00e547671fab9519f790c51f88de70d2b2a1f4..2669ad8c244017d237b93b438a95f9915f128e0c 100644 (file)
@@ -2342,13 +2342,7 @@ namespace __format
 
 // _GLIBCXX_RESOLVE_LIB_DEFECTS
 // P2510R3 Formatting pointers
-#if __glibcxx_format >= 202304L || ! defined __STRICT_ANSI__
-# define _GLIBCXX_P2518R3 1
-#else
-# define _GLIBCXX_P2518R3 0
-#endif
-
-#if _GLIBCXX_P2518R3
+#if __glibcxx_format >= 202304L
        __first = __spec._M_parse_zero_fill(__first, __last);
        if (__finished())
          return __first;
@@ -2360,11 +2354,9 @@ namespace __format
          {
            if (*__first == 'p')
              ++__first;
-#if _GLIBCXX_P2518R3
+#if __glibcxx_format >= 202304L
            else if (*__first == 'P')
            {
-             // _GLIBCXX_RESOLVE_LIB_DEFECTS
-             // P2510R3 Formatting pointers
              __spec._M_type = __format::_Pres_P;
              ++__first;
            }
@@ -2388,7 +2380,7 @@ namespace __format
          int __n = __ptr - __buf;
          __buf[0] = '0';
          __buf[1] = 'x';
-#if _GLIBCXX_P2518R3
+#if __glibcxx_format >= 202304L
          if (_M_spec._M_type == __format::_Pres_P)
            {
              __buf[1] = 'X';
@@ -2413,7 +2405,7 @@ namespace __format
            }
 #endif
 
-#if _GLIBCXX_P2518R3
+#if __glibcxx_format >= 202304L
          if (_M_spec._M_zero_fill)
            {
              size_t __width = _M_spec._M_get_width(__fc);
index 78cc1ab482ad7c2c3c74c0ae4ce81a12852e9062..5152bb0b0d06e5e30f023930ca8f69568f9db6fc 100644 (file)
@@ -458,7 +458,7 @@ test_pointer()
   s = std::format("{:20} {:20p}", p, pc);
   VERIFY( s == (str_int + ' ' + str_int) );
 
-#if __cplusplus > 202302L || ! defined __STRICT_ANSI__
+#if __cpp_lib_format >= 202304L
   // P2510R3 Formatting pointers
   s = std::format("{:06} {:07P} {:08p}", (void*)0, (const void*)0, nullptr);
   VERIFY( s == "0x0000 0X00000 0x000000" );
index 497427b54e5d31f939240dcac21b5410b01e4d9c..3b3201c2a47dc2a1b52918c97981a77c663a98d2 100644 (file)
@@ -266,8 +266,8 @@ test_pointer()
   VERIFY( ! is_std_format_spec_for<void*>("G") );
   VERIFY( ! is_std_format_spec_for<void*>("+p") );
 
-#if __cplusplus > 202302L || ! defined __STRICT_ANSI__
-  // As an extension, we support P2510R3 Formatting pointers
+#if __cpp_lib_format >= 202304L
+  // P2510R3 Formatting pointers
   VERIFY( is_std_format_spec_for<void*>("P") );
   VERIFY( is_std_format_spec_for<void*>("0p") );
   VERIFY( is_std_format_spec_for<void*>("0P") );