Re: [committed 7/8] libstdc++: Update (and revert) value of __cpp_lib_array_constexpr
On 22/04/20 22:59 +0100, Jonathan Wakely wrote: This macro should have been updated to 201811 when the last C++20 changes were implemented. However those changes are not enabled for C++17 mode, so the macro should only have the new value in C++20 mode. This change ensures that the macro is defined to 201603 for C++17 and 201811 for C++20. * include/bits/stl_iterator.h (__cpp_lib_array_constexpr): Define different values for C++17 and C++20, to indicate different feature sets. Update value for C++20 to indicate P1032R1 support. * include/std/version (__cpp_lib_array_constexpr): Likewise. * testsuite/23_containers/array/comparison_operators/constexpr.cc: Check feature test macro. * testsuite/23_containers/array/element_access/constexpr_c++17.cc: New test. * testsuite/23_containers/array/requirements/constexpr_fill.cc: Check feature test macro. * testsuite/23_containers/array/requirements/constexpr_iter.cc: Test in C++17 mode and check feature test macro. On second thoughts, changing __cpp_lib_array_constexpr for C++17 was wrong, it should have been left at 201803. This partially reverts my previous change related to this macro. The C++20 constexpr iterator requirements are always met by array:iterator, because it's just a pointer. So the macro can be set to 201803 even in C++17 mode. Tested powerpc64le-linux, committed to master. commit 40541efe1c063e9ce894b5f11ff727e4aec56e8b Author: Jonathan Wakely Date: Thu Apr 23 21:39:33 2020 +0100 libstdc++: Change __cpp_lib_array_constexpr for C++17 again This partially reverts my previous change related to this macro. The C++20 constexpr iterator requirements are always met by array:iterator, because it's just a pointer. So the macro can be set to 201803 even in C++17 mode. * include/bits/stl_iterator.h (__cpp_lib_array_constexpr): Revert value for C++17 to 201803L because P0858R0 is supported for C++17. * include/std/version (__cpp_lib_array_constexpr): Likewise. * testsuite/23_containers/array/element_access/constexpr_c++17.cc: Check for value corresponding to P0031R0 features being tested. * testsuite/23_containers/array/requirements/constexpr_iter.cc: Check for value corresponding to P0858R0 features being tested. diff --git a/libstdc++-v3/include/bits/stl_iterator.h b/libstdc++-v3/include/bits/stl_iterator.h index d7e85b84041..cc0b3e0a766 100644 --- a/libstdc++-v3/include/bits/stl_iterator.h +++ b/libstdc++-v3/include/bits/stl_iterator.h @@ -72,7 +72,7 @@ #if __cplusplus > 201703L # define __cpp_lib_array_constexpr 201811L #elif __cplusplus == 201703L -# define __cpp_lib_array_constexpr 201603L +# define __cpp_lib_array_constexpr 201803L #endif #if __cplusplus > 201703L diff --git a/libstdc++-v3/include/std/version b/libstdc++-v3/include/std/version index 1beb9aa938e..fa505f25e98 100644 --- a/libstdc++-v3/include/std/version +++ b/libstdc++-v3/include/std/version @@ -123,7 +123,7 @@ #if _GLIBCXX_HOSTED #define __cpp_lib_any 201606L #define __cpp_lib_apply 201603 -#define __cpp_lib_array_constexpr 201603L +#define __cpp_lib_array_constexpr 201803L #define __cpp_lib_as_const 201510 #define __cpp_lib_boyer_moore_searcher 201603 #define __cpp_lib_chrono 201611 diff --git a/libstdc++-v3/testsuite/23_containers/array/element_access/constexpr_c++17.cc b/libstdc++-v3/testsuite/23_containers/array/element_access/constexpr_c++17.cc index 56d1cf256be..dd69645833f 100644 --- a/libstdc++-v3/testsuite/23_containers/array/element_access/constexpr_c++17.cc +++ b/libstdc++-v3/testsuite/23_containers/array/element_access/constexpr_c++17.cc @@ -24,8 +24,6 @@ # error "Feature test macro for array constexpr is missing in " #elif __cpp_lib_array_constexpr < 201603L # error "Feature test macro for array constexpr has wrong value in " -#elif __cpp_lib_array_constexpr > 201603L && __cplusplus == 201703 -# error "Feature test macro for array constexpr has wrong value for C++17" #endif constexpr std::size_t test01() diff --git a/libstdc++-v3/testsuite/23_containers/array/requirements/constexpr_iter.cc b/libstdc++-v3/testsuite/23_containers/array/requirements/constexpr_iter.cc index a119937f773..566388405b6 100644 --- a/libstdc++-v3/testsuite/23_containers/array/requirements/constexpr_iter.cc +++ b/libstdc++-v3/testsuite/23_containers/array/requirements/constexpr_iter.cc @@ -22,12 +22,13 @@ #ifndef __cpp_lib_array_constexpr # error "Feature test macro for array constexpr is missing in " -#elif __cpp_lib_array_constexpr < 201603L +#elif __cpp_lib_array_constexpr < 201803L # error "Feature test macro for array constexpr has wrong value in " -#elif __cpp_lib_array_constexpr > 201603L && __cplusplus == 201703 -# error "Feature test macro for array constexpr has wrong value for C++17" #endif +// This test is compiled as C++17 because
[committed 7/8] libstdc++: Update (and revert) value of __cpp_lib_array_constexpr
This macro should have been updated to 201811 when the last C++20 changes were implemented. However those changes are not enabled for C++17 mode, so the macro should only have the new value in C++20 mode. This change ensures that the macro is defined to 201603 for C++17 and 201811 for C++20. * include/bits/stl_iterator.h (__cpp_lib_array_constexpr): Define different values for C++17 and C++20, to indicate different feature sets. Update value for C++20 to indicate P1032R1 support. * include/std/version (__cpp_lib_array_constexpr): Likewise. * testsuite/23_containers/array/comparison_operators/constexpr.cc: Check feature test macro. * testsuite/23_containers/array/element_access/constexpr_c++17.cc: New test. * testsuite/23_containers/array/requirements/constexpr_fill.cc: Check feature test macro. * testsuite/23_containers/array/requirements/constexpr_iter.cc: Test in C++17 mode and check feature test macro. --- libstdc++-v3/ChangeLog| 13 + libstdc++-v3/include/bits/stl_iterator.h | 6 +- libstdc++-v3/include/std/version | 4 +- .../array/comparison_operators/constexpr.cc | 6 ++ .../array/element_access/constexpr_c++17.cc | 57 +++ .../array/requirements/constexpr_fill.cc | 6 ++ .../array/requirements/constexpr_iter.cc | 12 +++- 7 files changed, 99 insertions(+), 5 deletions(-) create mode 100644 libstdc++-v3/testsuite/23_containers/array/element_access/constexpr_c++17.cc diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 4fec7b21029..cce254968fb 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,5 +1,18 @@ 2020-04-22 Jonathan Wakely + * include/bits/stl_iterator.h (__cpp_lib_array_constexpr): Define + different values for C++17 and C++20, to indicate different feature + sets. Update value for C++20 to indicate P1032R1 support. + * include/std/version (__cpp_lib_array_constexpr): Likewise. + * testsuite/23_containers/array/comparison_operators/constexpr.cc: + Check feature test macro. + * testsuite/23_containers/array/element_access/constexpr_c++17.cc: + New test. + * testsuite/23_containers/array/requirements/constexpr_fill.cc: Check + feature test macro. + * testsuite/23_containers/array/requirements/constexpr_iter.cc: Test + in C++17 mode and check feature test macro. + * include/std/utility (__cpp_lib_constexpr_algorithms): Do not define here. * testsuite/20_util/exchange/constexpr.cc: Do not expect macro to be diff --git a/libstdc++-v3/include/bits/stl_iterator.h b/libstdc++-v3/include/bits/stl_iterator.h index 652f51c6e7f..d7e85b84041 100644 --- a/libstdc++-v3/include/bits/stl_iterator.h +++ b/libstdc++-v3/include/bits/stl_iterator.h @@ -69,8 +69,10 @@ # include #endif -#if __cplusplus > 201402L -# define __cpp_lib_array_constexpr 201803 +#if __cplusplus > 201703L +# define __cpp_lib_array_constexpr 201811L +#elif __cplusplus == 201703L +# define __cpp_lib_array_constexpr 201603L #endif #if __cplusplus > 201703L diff --git a/libstdc++-v3/include/std/version b/libstdc++-v3/include/std/version index 85bc142bc38..57a05259d98 100644 --- a/libstdc++-v3/include/std/version +++ b/libstdc++-v3/include/std/version @@ -120,7 +120,7 @@ #if _GLIBCXX_HOSTED #define __cpp_lib_any 201606L #define __cpp_lib_apply 201603 -#define __cpp_lib_array_constexpr 201803 +#define __cpp_lib_array_constexpr 201603L #define __cpp_lib_as_const 201510 #define __cpp_lib_boyer_moore_searcher 201603 #define __cpp_lib_chrono 201611 @@ -184,6 +184,8 @@ #define __cpp_lib_unwrap_ref 201811L #if _GLIBCXX_HOSTED +#undef __cpp_lib_array_constexpr +#define __cpp_lib_array_constexpr 201811L #define __cpp_lib_assume_aligned 201811L #define __cpp_lib_bind_front 201907L #define __cpp_lib_integer_comparison_functions 202002L diff --git a/libstdc++-v3/testsuite/23_containers/array/comparison_operators/constexpr.cc b/libstdc++-v3/testsuite/23_containers/array/comparison_operators/constexpr.cc index fd6029b159e..0f3a4159dea 100644 --- a/libstdc++-v3/testsuite/23_containers/array/comparison_operators/constexpr.cc +++ b/libstdc++-v3/testsuite/23_containers/array/comparison_operators/constexpr.cc @@ -20,6 +20,12 @@ #include +#ifndef __cpp_lib_array_constexpr +# error "Feature test macro for array constexpr is missing in " +#elif __cpp_lib_array_constexpr < 201806L +# error "Feature test macro for array constexpr has wrong value in " +#endif + constexpr std::array a1{{1, 2, 3}}; constexpr std::array a2{{4, 5, 6}}; constexpr std::array a3{{1, 2, 4}}; diff --git a/libstdc++-v3/testsuite/23_containers/array/element_access/constexpr_c++17.cc b/libstdc++-v3/testsuite/23_containers/array/element_access/constexpr_c++17.cc new file mode 100644 index 000..56d1cf256be --- /dev/null +++