public inbox for libstdc++-cvs@sourceware.org
help / color / mirror / Atom feed
From: Peter Bergner <bergner@gcc.gnu.org>
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
Date: Fri,  4 Sep 2020 19:05:56 +0000 (GMT)	[thread overview]
Message-ID: <20200904190556.B794C3850425@sourceware.org> (raw)

https://gcc.gnu.org/g:c1d1dab64aa787e6e399c28ec9a852e1be85af0d

commit c1d1dab64aa787e6e399c28ec9a852e1be85af0d
Author: Jonathan Wakely <jwakely@redhat.com>
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  <jwakely@redhat.com>
 
+	* 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  <jwakely@redhat.com>
 
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 <type_traits>
 #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
+// <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>"
+#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) );
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 <array>
 
+#ifndef __cpp_lib_array_constexpr
+# error "Feature test macro for array constexpr is missing in <array>"
+#elif __cpp_lib_array_constexpr < 201803L
+# error "Feature test macro for array constexpr has wrong value in <array>"
+#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()
 {


                 reply	other threads:[~2020-09-04 19:05 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200904190556.B794C3850425@sourceware.org \
    --to=bergner@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    --cc=libstdc++-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).