libstdc++: Fix missing and incorrect feature test macros [PR105269]

libstdc++-v3/ChangeLog:

	PR libstdc++/105269
	* include/bits/stl_vector.h (__cpp_lib_constexpr_vector):
	Define.
	* include/c_compatibility/stdatomic.h (__cpp_lib_stdatomic_h):
	Define.
	* include/std/optional (__cpp_lib_optional): Define new value
	for C++23.
	(__cpp_lib_monadic_optional): Remove.
	* include/std/version (__cpp_lib_constexpr_vector): Define.
	(__cpp_lib_stdatomic_h): Define.
	(__cpp_lib_optional): Define new value for C++23.
	(__cpp_lib_monadic_optional): Remove.
	* testsuite/20_util/optional/monadic/and_then.cc: Adjust.
	* testsuite/20_util/optional/requirements.cc: Adjust for C++23.
	* testsuite/20_util/optional/version.cc: Likewise.
	* testsuite/23_containers/vector/cons/constexpr.cc: Check
	feature test macro.
	* testsuite/29_atomics/headers/stdatomic.h/c_compat.cc:
	Likewise.
	* testsuite/20_util/optional/monadic/version.cc: Removed.
	* testsuite/23_containers/vector/requirements/version.cc: New test.
	* testsuite/29_atomics/headers/stdatomic.h/version.cc: New test.
This commit is contained in:
Jonathan Wakely 2022-04-14 10:28:03 +01:00
parent 8369b4e4c6
commit d2f8208e9a
12 changed files with 54 additions and 23 deletions

View File

@ -62,8 +62,9 @@
#if __cplusplus >= 201103L
#include <initializer_list>
#endif
#if __cplusplus > 201703L
#if __cplusplus >= 202002L
# include <compare>
#define __cpp_lib_constexpr_vector 201907L
#endif
#include <debug/assertions.h>

View File

@ -32,6 +32,8 @@
#if __cplusplus > 202002L
#include <atomic>
#define __cpp_lib_stdatomic_h 202011L
#define _Atomic(_Tp) std::atomic<_Tp>
using std::memory_order;

View File

@ -60,10 +60,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
* @{
*/
#if __cplusplus == 201703L
# define __cpp_lib_optional 201606L
#else
#if __cplusplus > 202002L && __cpp_lib_concepts
# define __cpp_lib_optional 202110L
#elif __cplusplus >= 202002L
# define __cpp_lib_optional 202106L
#else
# define __cpp_lib_optional 201606L
#endif
template<typename _Tp>
@ -1043,9 +1045,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
return static_cast<_Tp>(std::forward<_Up>(__u));
}
#if __cplusplus > 202002L && __cpp_lib_concepts
#define __cpp_lib_monadic_optional 202110L
#if __cpp_lib_optional >= 202110L
// [optional.monadic]
template<typename _Fn>

View File

@ -257,6 +257,7 @@
#define __cpp_lib_constexpr_string_view 201811L
#define __cpp_lib_constexpr_tuple 201811L
#define __cpp_lib_constexpr_utility 201811L
#define __cpp_lib_constexpr_vector 201907L
#define __cpp_lib_erase_if 202002L
#define __cpp_lib_generic_unordered_lookup 201811L
#define __cpp_lib_interpolate 201902L
@ -312,7 +313,8 @@
#define __cpp_lib_invoke_r 202106L
#define __cpp_lib_ios_noreplace 202200L
#if __cpp_lib_concepts
# define __cpp_lib_monadic_optional 202110L
# undef __cpp_lib_optional
# define __cpp_lib_optional 202110L
#endif
#define __cpp_lib_move_only_function 202110L
#if __cpp_lib_span
@ -321,6 +323,7 @@
#if _GLIBCXX_HAVE_STACKTRACE
# define __cpp_lib_stacktrace 202011L
#endif
#define __cpp_lib_stdatomic_h 202011L
#define __cpp_lib_string_contains 202011L
#if _GLIBCXX_USE_CXX11_ABI // Only supported with cxx11-abi
# define __cpp_lib_string_resize_and_overwrite 202110L

View File

@ -3,9 +3,7 @@
#include <optional>
#ifndef __cpp_lib_monadic_optional
# error "Feature test macro for monadic optional is missing in <optional>"
#elif __cpp_lib_monadic_optional < 202110L
#if __cpp_lib_optional < 202110L
# error "Feature test macro for monadic optional has wrong value in <optional>"
#endif

View File

@ -1,10 +0,0 @@
// { dg-options "-std=gnu++23" }
// { dg-do preprocess { target c++23 } }
#include <version>
#ifndef __cpp_lib_monadic_optional
# error "Feature test macro for monadic optional is missing in <version>"
#elif __cpp_lib_monadic_optional < 202110L
# error "Feature test macro for monadic optional has wrong value in <version>"
#endif

View File

@ -23,8 +23,10 @@
# error "Feature test macro for optional is missing in <optional>"
#elif __cpp_lib_optional < 201606L
# error "Feature test macro for optional has wrong value in <optional>"
#elif __cplusplus >= 202002L && __cpp_lib_optional < 202106L
#elif __cplusplus == 202002L && __cpp_lib_optional != 202106L
# error "Feature test macro for optional has wrong value for C++20 in <optional>"
#elif __cplusplus > 202002L && __cpp_lib_optional != 202110L
# error "Feature test macro for optional has wrong value for C++23 in <version>"
#endif
#include <testsuite_hooks.h>

View File

@ -6,6 +6,8 @@
# error "Feature test macro for optional is missing in <version>"
#elif __cplusplus == 201703L && __cpp_lib_optional != 201606L
# error "Feature test macro for optional has wrong value for C++17 in <version>"
#elif __cplusplus >= 202002L && __cpp_lib_optional < 202106L
#elif __cplusplus == 202002L && __cpp_lib_optional != 202106L
# error "Feature test macro for optional has wrong value for C++20 in <version>"
#elif __cplusplus > 202002L && __cpp_lib_optional != 202110L
# error "Feature test macro for optional has wrong value for C++23 in <version>"
#endif

View File

@ -3,6 +3,13 @@
// { dg-xfail-if "not supported" { debug_mode } }
#include <vector>
#ifndef __cpp_lib_constexpr_vector
# error "Feature test macro for constexpr vector is missing in <vector>"
#elif __cpp_lib_constexpr_vector != 201907L
# error "Feature test macro for constexpr vector has wrong value in <vector>"
#endif
#include <testsuite_hooks.h>
#include <testsuite_iterators.h>

View File

@ -0,0 +1,10 @@
// { dg-options "-std=gnu++20" }
// { dg-do preprocess { target c++20 } }
#include <version>
#ifndef __cpp_lib_constexpr_vector
# error "Feature test macro for constexpr vector is missing in <version>"
#elif __cpp_lib_constexpr_vector != 201907L
# error "Feature test macro for constexpr vector has wrong value in <version>"
#endif

View File

@ -3,6 +3,12 @@
#include <stdatomic.h>
#ifndef __cpp_lib_stdatomic_h
# error "Feature test macro for stdatomic.h is missing in <stdatomic.h>"
#elif __cpp_lib_stdatomic_h != 202011L
# error "Feature test macro for stdatomic.h has wrong value in <stdatomic.h>"
#endif
#ifndef ATOMIC_BOOL_LOCK_FREE
#error ATOMIC_BOOL_LOCK_FREE is not defined in <stdatomic.h>
#endif

View File

@ -0,0 +1,10 @@
// { dg-options "-std=gnu++23" }
// { dg-do preprocess { target c++23 } }
#include <version>
#ifndef __cpp_lib_stdatomic_h
# error "Feature test macro for stdatomic.h is missing in <version>"
#elif __cpp_lib_stdatomic_h != 202011L
# error "Feature test macro for stdatomic.h has wrong value in <version>"
#endif