]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libstdc++: Define __cpp_lib_format_ranges in format header [PR109162]
authorTomasz Kamiński <tkaminsk@redhat.com>
Tue, 22 Apr 2025 07:56:42 +0000 (09:56 +0200)
committerTomasz Kamiński <tkaminsk@redhat.com>
Fri, 25 Apr 2025 11:02:04 +0000 (13:02 +0200)
As P2286R8 and P2585R1 as now fully implemented, we now define
__cpp_lib_format_ranges feature test macro with __cpp_lib_format_ranges.
This macro is provided only in <format>.

Uses of internal __glibcxx_format_ranges are also updated.

PR libstdc++/109162

libstdc++-v3/ChangeLog:

* include/bits/version.def (format_ranges): Remove no_stdname and
update value.
* include/bits/version.h: Regenerate.
* src/c++23/std.cc.in: Replace __glibcxx_format_ranges with
__cpp_lib_format_ranges.
* testsuite/std/format/formatter/lwg3944.cc: Likewise.
* testsuite/std/format/parse_ctx.cc: Likewise.
* testsuite/std/format/string.cc: Likewise.
* testsuite/std/format/ranges/feature_test.cc: New test.

Reviewed-by: Jonathan Wakely <jwakely@redhat.com>
Signed-off-by: Tomasz Kamiński <tkaminsk@redhat.com>
libstdc++-v3/include/bits/version.def
libstdc++-v3/include/bits/version.h
libstdc++-v3/src/c++23/std.cc.in
libstdc++-v3/testsuite/std/format/formatter/lwg3944.cc
libstdc++-v3/testsuite/std/format/parse_ctx.cc
libstdc++-v3/testsuite/std/format/ranges/feature_test.cc [new file with mode: 0644]
libstdc++-v3/testsuite/std/format/string.cc

index 0afaf0dec244efc580cb3e8064745527d8a062c9..737b3f421bf742cc9eb7074025a2d6f66472136b 100644 (file)
@@ -1416,9 +1416,8 @@ ftms = {
   // 202207 P2286R8 Formatting Ranges
   // 202207 P2585R1 Improving default container formatting
   // LWG3750 Too many papers bump __cpp_lib_format
-  no_stdname = true; // TODO remove
   values = {
-    v = 1; // TODO 202207
+    v = 202207;
     cxxmin = 23;
     hosted = yes;
   };
index 980fee641e9dae386cd1a0e76c73fc32996292f8..59ff0cee0436d9234e45b21f5b9ce07cc99897fe 100644 (file)
 
 #if !defined(__cpp_lib_format_ranges)
 # if (__cplusplus >= 202100L) && _GLIBCXX_HOSTED
-#  define __glibcxx_format_ranges 1L
+#  define __glibcxx_format_ranges 202207L
 #  if defined(__glibcxx_want_all) || defined(__glibcxx_want_format_ranges)
+#   define __cpp_lib_format_ranges 202207L
 #  endif
 # endif
 #endif /* !defined(__cpp_lib_format_ranges) && defined(__glibcxx_want_format_ranges) */
index ea50496b057c9f5e43bbc57abdafc73c147a4c96..930a489ff44b24637b4f1fe21e2cf58e20dc5424 100644 (file)
@@ -1319,8 +1319,7 @@ export namespace std
   using std::format_to_n;
   using std::format_to_n_result;
   using std::formatted_size;
-// FIXME __cpp_lib_format_ranges
-#if __cplusplus > 202002L
+#if __cpp_lib_format_ranges
   using std::formattable;
 #endif
   using std::formatter;
@@ -1336,8 +1335,7 @@ export namespace std
   using std::wformat_context;
   using std::wformat_parse_context;
   using std::wformat_string;
-// FIXME __cpp_lib_format_ranges
-#ifdef __glibcxx_format_ranges
+#ifdef __cpp_lib_format_ranges
   using std::format_kind;
   using std::range_format;
   using std::range_formatter;
index 1f3edc9cb030664ceffb27da771a4be2c9b9eea8..07e63af56529876f366a925af4e1667e06255476 100644 (file)
@@ -18,7 +18,7 @@ void test_lwg3944()
   std::format(L"{}", "hello"); // { dg-error "here" }
   std::format(L"{}", std::string_view("hello")); // { dg-error "here" }
   std::format(L"{}", std::string("hello")); // { dg-error "here" }
-#ifdef __glibcxx_format_ranges
+#ifdef __cpp_lib_format_ranges
   // LWG 3944 does not change this, it's still valid.
   std::format(L"{}", std::vector{'h', 'e', 'l', 'l', 'o'});
 #endif
index b338ac7b762d0e4a0524917141ca55cf62f6d629..b5dd7cdba7829bb8429c86dea6b629cd64d9e42a 100644 (file)
@@ -108,7 +108,7 @@ is_std_format_spec_for(std::string_view spec)
   }
 }
 
-#if __glibcxx_format_ranges
+#if __cpp_lib_format_ranges
 constexpr bool escaped_strings_supported = true;
 #else
 constexpr bool escaped_strings_supported = false;
diff --git a/libstdc++-v3/testsuite/std/format/ranges/feature_test.cc b/libstdc++-v3/testsuite/std/format/ranges/feature_test.cc
new file mode 100644 (file)
index 0000000..80d2cea
--- /dev/null
@@ -0,0 +1,9 @@
+// { dg-do preprocess { target c++23 } }
+
+#include <format>
+
+#ifndef __cpp_lib_format_ranges
+# error "Feature-test macro __cpp_lib_format_ranges missing in <format>"
+#elif __cpp_lib_format_ranges != 202207L
+# error "Feature-test macro __cpp_lib_format_ranges has wrong value in <format>"
+#endif
index 76614d4bc3e85020d17fb5028295d02bbd8566ae..ee987a15ec3ae61df33a3ac911472ceca336d45e 100644 (file)
@@ -62,7 +62,7 @@ test_indexing()
   VERIFY( ! is_format_string_for("{} {0}", 1) );
 }
 
-#if __glibcxx_format_ranges
+#if __cpp_lib_format_ranges
 constexpr bool escaped_strings_supported = true;
 #else
 constexpr bool escaped_strings_supported = false;