Don't unconditionally define feature test macros in <version>

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
This commit is contained in:
Jonathan Wakely 2018-07-31 23:31:14 +01:00 committed by Jonathan Wakely
parent b348c78aa4
commit ff27340046
5 changed files with 53 additions and 38 deletions

View 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.

View 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.

View 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

View 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
@ -97,13 +99,19 @@
#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
@ -115,8 +123,10 @@
#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

View 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