Commit e851aa17 by Jonathan Wakely

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.
parent 2025db69
2020-04-22 Jonathan Wakely <jwakely@redhat.com> 2020-04-22 Jonathan Wakely <jwakely@redhat.com>
* 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 * include/std/utility (__cpp_lib_constexpr_algorithms): Do not define
here. here.
* testsuite/20_util/exchange/constexpr.cc: Do not expect macro to be * testsuite/20_util/exchange/constexpr.cc: Do not expect macro to be
......
...@@ -69,8 +69,10 @@ ...@@ -69,8 +69,10 @@
# include <type_traits> # include <type_traits>
#endif #endif
#if __cplusplus > 201402L #if __cplusplus > 201703L
# define __cpp_lib_array_constexpr 201803 # define __cpp_lib_array_constexpr 201811L
#elif __cplusplus == 201703L
# define __cpp_lib_array_constexpr 201603L
#endif #endif
#if __cplusplus > 201703L #if __cplusplus > 201703L
......
...@@ -120,7 +120,7 @@ ...@@ -120,7 +120,7 @@
#if _GLIBCXX_HOSTED #if _GLIBCXX_HOSTED
#define __cpp_lib_any 201606L #define __cpp_lib_any 201606L
#define __cpp_lib_apply 201603 #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_as_const 201510
#define __cpp_lib_boyer_moore_searcher 201603 #define __cpp_lib_boyer_moore_searcher 201603
#define __cpp_lib_chrono 201611 #define __cpp_lib_chrono 201611
...@@ -184,6 +184,8 @@ ...@@ -184,6 +184,8 @@
#define __cpp_lib_unwrap_ref 201811L #define __cpp_lib_unwrap_ref 201811L
#if _GLIBCXX_HOSTED #if _GLIBCXX_HOSTED
#undef __cpp_lib_array_constexpr
#define __cpp_lib_array_constexpr 201811L
#define __cpp_lib_assume_aligned 201811L #define __cpp_lib_assume_aligned 201811L
#define __cpp_lib_bind_front 201907L #define __cpp_lib_bind_front 201907L
#define __cpp_lib_integer_comparison_functions 202002L #define __cpp_lib_integer_comparison_functions 202002L
......
...@@ -20,6 +20,12 @@ ...@@ -20,6 +20,12 @@
#include <array> #include <array>
#ifndef __cpp_lib_array_constexpr
# error "Feature test macro for array constexpr is missing in <array>"
#elif __cpp_lib_array_constexpr < 201806L
# error "Feature test macro for array constexpr has wrong value in <array>"
#endif
constexpr std::array<int, 3> a1{{1, 2, 3}}; constexpr std::array<int, 3> a1{{1, 2, 3}};
constexpr std::array<int, 3> a2{{4, 5, 6}}; constexpr std::array<int, 3> a2{{4, 5, 6}};
constexpr std::array<int, 3> a3{{1, 2, 4}}; constexpr std::array<int, 3> a3{{1, 2, 4}};
......
// { dg-options "-std=gnu++17" }
// { dg-do compile { target c++17 } }
// Copyright (C) 2011-2020 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
#include <array>
#ifndef __cpp_lib_array_constexpr
# error "Feature test macro for array constexpr is missing in <array>"
#elif __cpp_lib_array_constexpr < 201603L
# error "Feature test macro for array constexpr has wrong value in <array>"
#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()
{
// array
typedef std::array<std::size_t, 6> array_type;
array_type a = { { 0, 55, 66, 99, 4115, 2 } };
auto v1 = a[1];
auto v2 = a.at(2);
auto v3 = a.front();
auto v4 = a.back();
return v1 + v2 + v3 + v4;
}
static_assert( test01() == (55 + 66 + 0 + 2) );
constexpr std::size_t test02()
{
// array
typedef std::array<std::size_t, 6> array_type;
const array_type a = { { 0, 55, 66, 99, 4115, 2 } };
auto v1 = a[1];
auto v2 = a.at(2);
auto v3 = a.front();
auto v4 = a.back();
return v1 + v2 + v3 + v4;
}
static_assert( test02() == (55 + 66 + 0 + 2) );
...@@ -20,6 +20,12 @@ ...@@ -20,6 +20,12 @@
#include <array> #include <array>
#ifndef __cpp_lib_array_constexpr
# error "Feature test macro for array constexpr is missing in <array>"
#elif __cpp_lib_array_constexpr < 201811L
# error "Feature test macro for array constexpr has wrong value in <array>"
#endif
constexpr bool constexpr bool
test_array() test_array()
{ {
......
// { dg-options "-std=gnu++2a" } // { dg-options "-std=gnu++17" }
// { dg-do compile { target c++2a } } // { dg-do compile { target c++17 } }
// //
// Copyright (C) 2019-2020 Free Software Foundation, Inc. // Copyright (C) 2019-2020 Free Software Foundation, Inc.
// //
...@@ -20,6 +20,14 @@ ...@@ -20,6 +20,14 @@
#include <array> #include <array>
#ifndef __cpp_lib_array_constexpr
# error "Feature test macro for array constexpr is missing in <array>"
#elif __cpp_lib_array_constexpr < 201603L
# error "Feature test macro for array constexpr has wrong value in <array>"
#elif __cpp_lib_array_constexpr > 201603L && __cplusplus == 201703
# error "Feature test macro for array constexpr has wrong value for C++17"
#endif
constexpr int constexpr int
test() test()
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment