From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1464) id B794C3850425; Fri, 4 Sep 2020 19:05:56 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B794C3850425 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1599246356; bh=N2IJp5hOBuxp6AGgBvPXvA54Rq1fZQcDQy6+Gb/x1As=; h=From:To:Subject:Date:From; b=nAa+OlwG4XdknH1YgBOXmTizOFPthh5K6p83UefCOYCV8Mc0tGrP+KP30/f0hsiAS 24c/pV4jyYGkCRcUMgo8ZAdFL4xAofvBRegRI0pYrWviiTh77HOtKkeWTkoGK/wCeA 2NjY9BODbU1f9H4mvglogVQs+tdN3bwsoDJkJWsM= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Peter Bergner To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org Subject: [gcc(refs/vendors/ibm/heads/gcc-9-branch)] libstdc++: Update __cpp_lib_array_constexpr and __cpp_lib_string_view X-Act-Checkin: gcc X-Git-Author: Jonathan Wakely X-Git-Refname: refs/vendors/ibm/heads/gcc-9-branch X-Git-Oldrev: 46790405c5204d0c00501b1b972138d1d5481ba9 X-Git-Newrev: c1d1dab64aa787e6e399c28ec9a852e1be85af0d Message-Id: <20200904190556.B794C3850425@sourceware.org> Date: Fri, 4 Sep 2020 19:05:56 +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, 04 Sep 2020 19:05:56 -0000 https://gcc.gnu.org/g:c1d1dab64aa787e6e399c28ec9a852e1be85af0d commit c1d1dab64aa787e6e399c28ec9a852e1be85af0d Author: Jonathan Wakely Date: Thu Apr 23 18:42:04 2020 +0100 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: --- libstdc++-v3/ChangeLog | 10 ++++ libstdc++-v3/include/bits/stl_iterator.h | 4 +- libstdc++-v3/include/std/string_view | 2 +- libstdc++-v3/include/std/version | 4 +- .../array/element_access/constexpr_c++17.cc | 55 ++++++++++++++++++++++ .../array/requirements/constexpr_iter.cc | 13 ++++- 6 files changed, 81 insertions(+), 7 deletions(-) diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 4589039deb5..ff8856fc0c3 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 e9d90fa01f4..11dd9b0fd4c 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 bca3af89836..4d90438e6be 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 fb0440d4e12..c54f6ffbb4c 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 00000000000..dd69645833f --- /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 208078c3b5a..7ede36073e1 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() {