]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libstdc++: Define __cpp_lib_define_static [PR123921]
authorJakub Jelinek <jakub@redhat.com>
Tue, 3 Feb 2026 13:22:46 +0000 (14:22 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Tue, 3 Feb 2026 13:22:46 +0000 (14:22 +0100)
I've totally missed the P3491R3 paper (define_static_{string,object,array})
comes with its own feature test macro - __cpp_lib_define_static 202506
which should appear in <version> and <meta>.
The paper contains 3 parts, std::is_string_literal,
std::meta::reflect_constant_{string,array} and
std::define_static_{string,object,array}.
The first part is implementable without reflection, the third part in theory
would be also implementable without reflection but usually will be (and in
libstdc++ is) implemented using reflection, and the middle part is really
part of reflection.  So dunno how useful this FTM actually is, maybe just
for cases where some implementation does implement reflection and doesn't
implement this paper for a while.

Anyway, the FTM is in C++26 draft, so this patch adds it, with the same
condition as __cpp_lib_reflection.

2026-02-03  Jakub Jelinek  <jakub@redhat.com>

PR libstdc++/123921
* include/bits/version.def (define_static): New with the
same values as reflection.
* include/bits/version.h: Regenerate.
* include/std/meta: Define also __glibcxx_want_define_static before
including bits/version.h.

* g++.dg/reflect/feat2.C: Add also test for __cpp_lib_define_static.
* g++.dg/reflect/feat3.C: New test.

gcc/testsuite/g++.dg/reflect/feat2.C
gcc/testsuite/g++.dg/reflect/feat3.C [new file with mode: 0644]
libstdc++-v3/include/bits/version.def
libstdc++-v3/include/bits/version.h
libstdc++-v3/include/std/meta

index 902732b08247860896dec08411d61ecffe295ba0..dc4c82cdaab98616ea7b349ac0730d9643138ae2 100644 (file)
@@ -9,3 +9,9 @@
 #elif __cpp_lib_reflection != 202506
 #  error "__cpp_lib_reflection != 202506"
 #endif
+
+#ifndef __cpp_lib_define_static
+#  error "__cpp_lib_define_static"
+#elif __cpp_lib_define_static != 202506
+#  error "__cpp_lib_define_static != 202506"
+#endif
diff --git a/gcc/testsuite/g++.dg/reflect/feat3.C b/gcc/testsuite/g++.dg/reflect/feat3.C
new file mode 100644 (file)
index 0000000..68b72e2
--- /dev/null
@@ -0,0 +1,17 @@
+// { dg-do compile { target c++26 } }
+// { dg-additional-options "-freflection" }
+// Test feature test macros.
+
+#include <meta>
+
+#ifndef __cpp_lib_reflection
+#  error "__cpp_lib_reflection"
+#elif __cpp_lib_reflection != 202506
+#  error "__cpp_lib_reflection != 202506"
+#endif
+
+#ifndef __cpp_lib_define_static
+#  error "__cpp_lib_define_static"
+#elif __cpp_lib_define_static != 202506
+#  error "__cpp_lib_define_static != 202506"
+#endif
index 8c5f4bb7c4c5fa66205a2926d7a70164fe112dc3..ba0ef5aecfdc84c3a6bf3c8ecaa69766b900d94a 100644 (file)
@@ -2271,6 +2271,16 @@ ftms = {
   };
 };
 
+ftms = {
+  name = define_static;
+  values = {
+    v = 202506;
+    cxxmin = 26;
+    extra_cond = "__cpp_impl_reflection >= 202506L";
+    cxx11abi = yes;
+  };
+};
+
 ftms = {
   name = is_implicit_lifetime;
   values = {
index 985701447beedb2bd03840f6baa83b55e316b671..74d1a28f75c49b8ab6783f23a16322503e70b5da 100644 (file)
 #endif /* !defined(__cpp_lib_reflection) */
 #undef __glibcxx_want_reflection
 
+#if !defined(__cpp_lib_define_static)
+# if (__cplusplus >  202302L) && _GLIBCXX_USE_CXX11_ABI && (__cpp_impl_reflection >= 202506L)
+#  define __glibcxx_define_static 202506L
+#  if defined(__glibcxx_want_all) || defined(__glibcxx_want_define_static)
+#   define __cpp_lib_define_static 202506L
+#  endif
+# endif
+#endif /* !defined(__cpp_lib_define_static) */
+#undef __glibcxx_want_define_static
+
 #if !defined(__cpp_lib_is_implicit_lifetime)
 # if (__cplusplus >= 202100L) && (__has_builtin(__builtin_is_implicit_lifetime))
 #  define __glibcxx_is_implicit_lifetime 202302L
index 033746a40349bb3a7ff4598667de82cdbbf59f54..59a678037a164117098b063c39719ed6f06aaca0 100644 (file)
@@ -34,6 +34,7 @@
 #endif
 
 #define __glibcxx_want_reflection
+#define __glibcxx_want_define_static
 #include <bits/version.h>
 
 #if __glibcxx_reflection >= 202506L // C++ >= 26 && __cpp_impl_reflection