Don't unconditionally define feature test macros in <version>
authorJonathan Wakely <jwakely@redhat.com>
Tue, 31 Jul 2018 22:31:14 +0000 (23:31 +0100)
committerJonathan Wakely <redi@gcc.gnu.org>
Tue, 31 Jul 2018 22:31:14 +0000 (23:31 +0100)
The macro definitions in <version> should depend on the same
preprocessor conditions as the original macros in other headers.
Otherwise <version> can define macros that imply the availability of
features that are not actually defined.

This fix is incomplete, as __cpp_lib_filesystem should depend on whether
libstdc++fs.a is supported, and several macros should only be defined
when _GLIBCXX_HOSTED is defined. Also, the feature test macros should
define their value as type long, but most are type int.

* include/bits/c++config (_GLIBCXX_HAVE_BUILTIN_HAS_UNIQ_OBJ_REP)
(_GLIBCXX_HAVE_BUILTIN_IS_AGGREGATE): Move definitions here.
(_GLIBCXX_HAVE_BUILTIN_LAUNDER): Likewise. Use !__is_identifier
instead of __has_builtin.
* include/std/type_traits (_GLIBCXX_HAVE_BUILTIN_HAS_UNIQ_OBJ_REP)
(_GLIBCXX_HAVE_BUILTIN_IS_AGGREGATE): Remove definitions from here.
* include/std/version [!_GLIBCXX_HAS_GTHREADS]
(__cpp_lib_shared_timed_mutex, __cpp_lib_scoped_lock)
(__cpp_lib_shared_mutex): Don't define when Gthreads not in use.
[!_GLIBCXX_HAVE_BUILTIN_HAS_UNIQ_OBJ_REP]
(__cpp_lib_has_unique_object_representations): Don't define when
builtin not available.
[!_GLIBCXX_HAVE_BUILTIN_IS_AGGREGATE] (__cpp_lib_is_aggregate):
Likewise.
[!_GLIBCXX_HAVE_BUILTIN_LAUNDER] (__cpp_lib_launder): Likewise.
* libsupc++/new (_GLIBCXX_HAVE_BUILTIN_LAUNDER): Remove definition
from here.

From-SVN: r263184

libstdc++-v3/ChangeLog
libstdc++-v3/include/bits/c++config
libstdc++-v3/include/std/type_traits
libstdc++-v3/include/std/version
libstdc++-v3/libsupc++/new

index f2f7676b63f87fd7635fdc14affb0fd77adad14f..b29778ad38e94092da6c154cc71aa65aaf769699 100644 (file)
@@ -1,5 +1,23 @@
 2018-07-31  Jonathan Wakely  <jwakely@redhat.com>
 
+       * include/bits/c++config (_GLIBCXX_HAVE_BUILTIN_HAS_UNIQ_OBJ_REP)
+       (_GLIBCXX_HAVE_BUILTIN_IS_AGGREGATE): Move definitions here.
+       (_GLIBCXX_HAVE_BUILTIN_LAUNDER): Likewise. Use !__is_identifier
+       instead of __has_builtin.
+       * include/std/type_traits (_GLIBCXX_HAVE_BUILTIN_HAS_UNIQ_OBJ_REP)
+       (_GLIBCXX_HAVE_BUILTIN_IS_AGGREGATE): Remove definitions from here.
+       * include/std/version [!_GLIBCXX_HAS_GTHREADS]
+       (__cpp_lib_shared_timed_mutex, __cpp_lib_scoped_lock)
+       (__cpp_lib_shared_mutex): Don't define when Gthreads not in use.
+       [!_GLIBCXX_HAVE_BUILTIN_HAS_UNIQ_OBJ_REP]
+       (__cpp_lib_has_unique_object_representations): Don't define when
+       builtin not available.
+       [!_GLIBCXX_HAVE_BUILTIN_IS_AGGREGATE] (__cpp_lib_is_aggregate):
+       Likewise.
+       [!_GLIBCXX_HAVE_BUILTIN_LAUNDER] (__cpp_lib_launder): Likewise.
+       * libsupc++/new (_GLIBCXX_HAVE_BUILTIN_LAUNDER): Remove definition
+       from here.
+
        * doc/xml/manual/test.xml: Improve documentation on writing tests for
        newer standards.
        * doc/xml/manual/using.xml: Document all headers for C++11 and later.
index c0b89f481d8982250def06a82c071990a6bc2f0f..d499d32b51e3a13e130df5edca7dff95bf26240e 100644 (file)
@@ -622,4 +622,22 @@ namespace std
 #define _GLIBCXX_USE_FLOAT128
 #endif
 
+#if __GNUC__ >= 7
+// Assume these are available if the compiler claims to be a recent GCC:
+# define _GLIBCXX_HAVE_BUILTIN_HAS_UNIQ_OBJ_REP 1
+# define _GLIBCXX_HAVE_BUILTIN_IS_AGGREGATE 1
+# define _GLIBCXX_HAVE_BUILTIN_LAUNDER 1
+#elif defined(__is_identifier)
+// For non-GNU compilers:
+# if ! __is_identifier(__has_unique_object_representations)
+#  define _GLIBCXX_HAVE_BUILTIN_HAS_UNIQ_OBJ_REP 1
+# endif
+# if ! __is_identifier(__is_aggregate)
+#  define _GLIBCXX_HAVE_BUILTIN_IS_AGGREGATE 1
+# endif
+# if ! __is_identifier(__builtin_launder)
+#  define _GLIBCXX_HAVE_BUILTIN_LAUNDER 1
+# endif
+#endif // GCC
+
 // End of prewritten config; the settings discovered at configure time follow.
index aaa554c6200079a503cedb688ef1e24c20d4d460..4f89723d468e167549eadf915b1186713c7a96dd 100644 (file)
@@ -2956,15 +2956,6 @@ template <typename _Base, typename _Derived>
 template <typename _From, typename _To>
   inline constexpr bool is_convertible_v = is_convertible<_From, _To>::value;
 
-#if __GNUC__ >= 7
-# define _GLIBCXX_HAVE_BUILTIN_HAS_UNIQ_OBJ_REP 1
-#elif defined(__is_identifier)
-// For non-GNU compilers:
-# if ! __is_identifier(__has_unique_object_representations)
-#  define _GLIBCXX_HAVE_BUILTIN_HAS_UNIQ_OBJ_REP 1
-# endif
-#endif
-
 #ifdef _GLIBCXX_HAVE_BUILTIN_HAS_UNIQ_OBJ_REP
 # define __cpp_lib_has_unique_object_representations 201606
   /// has_unique_object_representations
@@ -2979,19 +2970,9 @@ template <typename _From, typename _To>
     inline constexpr bool has_unique_object_representations_v
       = has_unique_object_representations<_Tp>::value;
 #endif
-#undef _GLIBCXX_HAVE_BUILTIN_HAS_UNIQ_OBJ_REP
-
-#if __GNUC__ >= 7
-# define _GLIBCXX_HAVE_BUILTIN_IS_AGGREGATE 1
-#elif defined(__is_identifier)
-// For non-GNU compilers:
-# if ! __is_identifier(__is_aggregate)
-#  define _GLIBCXX_HAVE_BUILTIN_IS_AGGREGATE 1
-# endif
-#endif
 
 #ifdef _GLIBCXX_HAVE_BUILTIN_IS_AGGREGATE
-#define __cpp_lib_is_aggregate 201703
+# define __cpp_lib_is_aggregate 201703
   /// is_aggregate
   template<typename _Tp>
     struct is_aggregate
@@ -3001,8 +2982,6 @@ template <typename _From, typename _To>
   template<typename _Tp>
     inline constexpr bool is_aggregate_v = is_aggregate<_Tp>::value;
 #endif
-#undef _GLIBCXX_HAVE_BUILTIN_IS_AGGREGATE
-
 #endif // C++17
 
 #if __cplusplus > 201703L
index 0c26d9b6a7bc1969554984a7457c67609f869d9b..0e054c47bf83936ac07e1eb0fb64bf0af7a7aebf 100644 (file)
@@ -73,7 +73,9 @@
 #define __cpp_lib_make_unique 201304
 #define __cpp_lib_quoted_string_io 201304
 #define __cpp_lib_robust_nonmodifying_seq_ops 201304
-#define __cpp_lib_shared_timed_mutex 201402
+#ifdef _GLIBCXX_HAS_GTHREADS
+# define __cpp_lib_shared_timed_mutex 201402
+#endif
 #define __cpp_lib_string_udls 201304
 #define __cpp_lib_transformation_trait_aliases 201304
 #define __cpp_lib_transparent_operators 201510
 #define __cpp_lib_filesystem 201703
 #define __cpp_lib_gcd 201606
 #define __cpp_lib_gcd_lcm 201606
-#define __cpp_lib_has_unique_object_representations 201606
+#ifdef _GLIBCXX_HAVE_BUILTIN_HAS_UNIQ_OBJ_REP
+# define __cpp_lib_has_unique_object_representations 201606
+#endif
 #define __cpp_lib_hypot 201603
 #define __cpp_lib_invoke 201411
-#define __cpp_lib_is_aggregate 201703
+#ifdef _GLIBCXX_HAVE_BUILTIN_IS_AGGREGATE
+# define __cpp_lib_is_aggregate 201703
+#endif
 #define __cpp_lib_is_invocable 201703
 #define __cpp_lib_is_swappable 201603
-#define __cpp_lib_launder 201606
+#ifdef _GLIBCXX_HAVE_BUILTIN_LAUNDER
+# define __cpp_lib_launder 201606
+#endif
 #define __cpp_lib_lcm 201606
 #define __cpp_lib_logical_traits 201510
 #define __cpp_lib_make_from_tuple 201606
 #define __cpp_lib_not_fn 201603
 #define __cpp_lib_optional 201603
 #define __cpp_lib_sample 201603
-#define __cpp_lib_scoped_lock 201703
-#define __cpp_lib_shared_mutex 201505
+#ifdef _GLIBCXX_HAS_GTHREADS
+# define __cpp_lib_scoped_lock 201703
+# define __cpp_lib_shared_mutex 201505
+#endif
 #define __cpp_lib_shared_ptr_weak_type 201606
 #define __cpp_lib_string_view 201603
 #define __cpp_lib_type_trait_variable_templates 201510L
index 73483c8a92c7b2f6cfb278d3e3e21d442d6d66b3..82d884d95d378f4b2b03df04ef11e52648bdc64e 100644 (file)
@@ -182,15 +182,6 @@ inline void operator delete[](void*, void*) _GLIBCXX_USE_NOEXCEPT { }
 } // extern "C++"
 
 #if __cplusplus >= 201703L
-#if __GNUC__ >= 7
-#  define _GLIBCXX_HAVE_BUILTIN_LAUNDER 1
-#elif defined __has_builtin
-// For non-GNU compilers:
-# if __has_builtin(__builtin_launder)
-#  define _GLIBCXX_HAVE_BUILTIN_LAUNDER 1
-# endif
-#endif
-
 #ifdef _GLIBCXX_HAVE_BUILTIN_LAUNDER
 namespace std
 {
@@ -215,7 +206,6 @@ namespace std
   void launder(const volatile void*) = delete;
 }
 #endif // _GLIBCXX_HAVE_BUILTIN_LAUNDER
-#undef _GLIBCXX_HAVE_BUILTIN_LAUNDER
 #endif // C++17
 
 #pragma GCC visibility pop