From: Jonathan Wakely Date: Thu, 23 Apr 2020 17:42:04 +0000 (+0100) Subject: libstdc++: Update __cpp_lib_array_constexpr and __cpp_lib_string_view X-Git-Tag: misc/first-auto-changelog-9~91 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=c1d1dab64aa787e6e399c28ec9a852e1be85af0d;p=thirdparty%2Fgcc.git libstdc++: Update __cpp_lib_array_constexpr and __cpp_lib_string_view The C++20 P0858R0 changes are supported even in C++17 (because array and string_view iterators are just pointers), so the feature test macros can be defined to 201803 for C++17. * include/bits/stl_iterator.h (__cpp_lib_array_constexpr): Update value to indicate P0858R0 support. * include/std/string_view (__cpp_lib_string_view): Likewise. * include/std/version (__cpp_lib_array_constexpr) (__cpp_lib_string_view): Likewise. * testsuite/23_containers/array/element_access/constexpr_c++17.cc: New test. * testsuite/23_containers/array/requirements/constexpr_iter.cc: Test in C++17 mode and check feature test macro. --- diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 4589039deb59..ff8856fc0c3c 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,5 +1,15 @@ 2020-04-23 Jonathan Wakely + * include/bits/stl_iterator.h (__cpp_lib_array_constexpr): Update + value to indicate P0858R0 support. + * include/std/string_view (__cpp_lib_string_view): Likewise. + * include/std/version (__cpp_lib_array_constexpr) + (__cpp_lib_string_view): Likewise. + * testsuite/23_containers/array/element_access/constexpr_c++17.cc: + New test. + * testsuite/23_containers/array/requirements/constexpr_iter.cc: Test + in C++17 mode and check feature test macro. + Backport from mainline 2020-04-22 Jonathan Wakely diff --git a/libstdc++-v3/include/bits/stl_iterator.h b/libstdc++-v3/include/bits/stl_iterator.h index e9d90fa01f40..11dd9b0fd4ca 100644 --- a/libstdc++-v3/include/bits/stl_iterator.h +++ b/libstdc++-v3/include/bits/stl_iterator.h @@ -69,8 +69,8 @@ # include #endif -#if __cplusplus > 201402L -# define __cpp_lib_array_constexpr 201603 +#if __cplusplus >= 201703L +# define __cpp_lib_array_constexpr 201803L #endif namespace std _GLIBCXX_VISIBILITY(default) diff --git a/libstdc++-v3/include/std/string_view b/libstdc++-v3/include/std/string_view index bca3af89836c..4d90438e6be1 100644 --- a/libstdc++-v3/include/std/string_view +++ b/libstdc++-v3/include/std/string_view @@ -47,7 +47,7 @@ namespace std _GLIBCXX_VISIBILITY(default) { _GLIBCXX_BEGIN_NAMESPACE_VERSION -#define __cpp_lib_string_view 201603 +#define __cpp_lib_string_view 201803 // Helper for basic_string and basic_string_view members. constexpr size_t diff --git a/libstdc++-v3/include/std/version b/libstdc++-v3/include/std/version index fb0440d4e126..c54f6ffbb4c9 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 201603 +#define __cpp_lib_array_constexpr 201803L #define __cpp_lib_as_const 201510 #define __cpp_lib_boyer_moore_searcher 201603 #define __cpp_lib_chrono 201611 @@ -153,7 +153,7 @@ # define __cpp_lib_shared_mutex 201505 #endif #define __cpp_lib_shared_ptr_weak_type 201606 -#define __cpp_lib_string_view 201603 +#define __cpp_lib_string_view 201803 // #define __cpp_lib_to_chars 201611L #define __cpp_lib_unordered_map_insertion 201411 // non-standard macro #define __cpp_lib_unordered_map_try_emplace 201411 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 000000000000..dd69645833f6 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/array/element_access/constexpr_c++17.cc @@ -0,0 +1,55 @@ +// { 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 " +#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_iter.cc b/libstdc++-v3/testsuite/23_containers/array/requirements/constexpr_iter.cc index 208078c3b5aa..7ede36073e19 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 Free Software Foundation, Inc. // @@ -20,6 +20,15 @@ #include +#ifndef __cpp_lib_array_constexpr +# error "Feature test macro for array constexpr is missing in " +#elif __cpp_lib_array_constexpr < 201803L +# error "Feature test macro for array constexpr has wrong value in " +#endif + +// This test is compiled as C++17 because array::iterator is just a pointer, +// so always meets the C++20 constexpr iterator requirements, even in C++17. + constexpr int test() {