From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1984) id 8326B39E101D; Fri, 17 Jul 2020 14:52:26 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8326B39E101D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1594997546; bh=NpO2hj0ea8YJQYJqUHlrEcCP5oLqeH6UASCAkhBHAEA=; h=From:To:Subject:Date:From; b=h6QDBtPtLJn+TENQQsV55SLE4/RhjJOuspVU5fuHzz6GdEbN5+uLUnf6wy4nPj9Kk 2fKdshWsXfJrnJlHOEBQwvf+pt1XI351cVaaXKQzuvD+WCOQw54uuTion2QR9Fzhwp hjsuoWwf7QlC9927n32d/eMfkJtsWnymDtq19Vo0= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Tamar Christina To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org Subject: [gcc(refs/vendors/ARM/heads/arm-perf-staging)] libstdc++: Update (and revert) value of __cpp_lib_array_constexpr X-Act-Checkin: gcc X-Git-Author: Jonathan Wakely X-Git-Refname: refs/vendors/ARM/heads/arm-perf-staging X-Git-Oldrev: 2025db692e9ed1192f831bc122413a226987515c X-Git-Newrev: e851aa1703c3d911720d8f9bee68a521abe588f7 Message-Id: <20200717145226.8326B39E101D@sourceware.org> Date: Fri, 17 Jul 2020 14:52:26 +0000 (GMT) X-BeenThere: libstdc++-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libstdc++-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 17 Jul 2020 14:52:26 -0000 https://gcc.gnu.org/g:e851aa1703c3d911720d8f9bee68a521abe588f7 commit e851aa1703c3d911720d8f9bee68a521abe588f7 Author: Jonathan Wakely Date: Wed Apr 22 22:54:35 2020 +0100 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. Diff: --- 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(-) 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 00000000000..56d1cf256be --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/array/element_access/constexpr_c++17.cc @@ -0,0 +1,57 @@ +// { 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 +// . + +#include + +#ifndef __cpp_lib_array_constexpr +# 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() +{ + // array + typedef std::array 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 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) ); diff --git a/libstdc++-v3/testsuite/23_containers/array/requirements/constexpr_fill.cc b/libstdc++-v3/testsuite/23_containers/array/requirements/constexpr_fill.cc index c7f9dd7b7b5..bb696346537 100644 --- a/libstdc++-v3/testsuite/23_containers/array/requirements/constexpr_fill.cc +++ b/libstdc++-v3/testsuite/23_containers/array/requirements/constexpr_fill.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 < 201811L +# error "Feature test macro for array constexpr has wrong value in " +#endif + constexpr bool test_array() { 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 f3f9ae6ea41..a119937f773 100644 --- a/libstdc++-v3/testsuite/23_containers/array/requirements/constexpr_iter.cc +++ b/libstdc++-v3/testsuite/23_containers/array/requirements/constexpr_iter.cc @@ -1,5 +1,5 @@ -// { dg-options "-std=gnu++2a" } -// { dg-do compile { target c++2a } } +// { dg-options "-std=gnu++17" } +// { dg-do compile { target c++17 } } // // Copyright (C) 2019-2020 Free Software Foundation, Inc. // @@ -20,6 +20,14 @@ #include +#ifndef __cpp_lib_array_constexpr +# 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 int test() {