]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libstdc++: Make std::variant work with Clang in C++20 mode [PR103891]
authorJonathan Wakely <jwakely@redhat.com>
Mon, 10 Jan 2022 17:28:19 +0000 (17:28 +0000)
committerJonathan Wakely <jwakely@redhat.com>
Tue, 11 Jan 2022 13:22:35 +0000 (13:22 +0000)
Clang has some bugs with destructors that use constraints to be
conditionally trivial, so disable the P2231R1 constexpr changes to
std::variant unless the compiler is GCC 12 or later.

If/when P2493R0 gets accepted and implemented by G++ we can remove the
__GNUC__ check and use __cpp_concepts >= 202002 instead.

libstdc++-v3/ChangeLog:

PR libstdc++/103891
* include/bits/c++config (_GLIBCXX_HAVE_COND_TRIVIAL_SPECIAL_MEMBERS):
Define.
* include/std/variant (__cpp_lib_variant): Only define C++20
value when the compiler is known to support conditionally
trivial destructors.
* include/std/version (__cpp_lib_variant): Likewise.

libstdc++-v3/include/bits/c++config
libstdc++-v3/include/std/variant
libstdc++-v3/include/std/version

index c64b61b3c90ace32d92f8d649a5670585c1e630f..b197349f9769e1d8f229665ccffd05c15c3565a9 100644 (file)
@@ -810,6 +810,11 @@ namespace std
 
 #undef _GLIBCXX_HAS_BUILTIN
 
+#if __cplusplus >= 202002L && __cpp_concepts && __GNUC__ >= 12
+// XXX workaround for missing feature test macro for P0848R3 (see P2493R0).
+# define _GLIBCXX_HAVE_COND_TRIVIAL_SPECIAL_MEMBERS 1
+#endif
+
 // PSTL configuration
 
 #if __cplusplus >= 201703L
index d74939eddc3a9dcb06f2e39ad62fe86421dd5048..c41f9f27e000f595545bbe8f97606ade768b92dd 100644 (file)
 #include <bits/stl_iterator_base_funcs.h>
 #include <bits/stl_construct.h>
 #include <bits/utility.h> // in_place_index_t
-#if __cplusplus == 201703L
+#ifndef _GLIBCXX_HAVE_COND_TRIVIAL_SPECIAL_MEMBERS
 # include <ext/aligned_buffer.h>
-#else
+#endif
+#if __cplusplus >= 202002L
 # include <compare>
 #endif
 
@@ -54,7 +55,7 @@ namespace std _GLIBCXX_VISIBILITY(default)
 {
 _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
-#if __cplusplus >= 202002L && __cpp_concepts
+#ifdef _GLIBCXX_HAVE_COND_TRIVIAL_SPECIAL_MEMBERS
 // P2231R1 constexpr needs constexpr unions and constrained destructors.
 # define __cpp_lib_variant 202106L
 #else
index f421056964e2d6219f9ecab0a84cde41ddb5c771..012d78e3b6baac6bea814238f79380d5b1666be7 100644 (file)
 # define __cpp_lib_to_chars 201611L
 #endif
 #define __cpp_lib_unordered_map_try_emplace 201411
-#if __cplusplus == 201703L || ! __cpp_concepts // N.B. updated value in C++20
+#ifndef _GLIBCXX_HAVE_COND_TRIVIAL_SPECIAL_MEMBERS
+// N.B. updated value in C++20
 # define __cpp_lib_variant 202102L
 #endif
 #endif
 # endif
 #define __cpp_lib_to_address 201711L
 #define __cpp_lib_to_array 201907L
-#if __cpp_concepts
+#ifdef _GLIBCXX_HAVE_COND_TRIVIAL_SPECIAL_MEMBERS
 # define __cpp_lib_variant 202106L
 #endif
 #endif