]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libstdc++: Update __cpp_lib_array_constexpr and __cpp_lib_string_view
authorJonathan Wakely <jwakely@redhat.com>
Thu, 23 Apr 2020 17:42:04 +0000 (18:42 +0100)
committerJonathan Wakely <jwakely@redhat.com>
Thu, 23 Apr 2020 18:00:17 +0000 (19:00 +0100)
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.

libstdc++-v3/ChangeLog
libstdc++-v3/include/bits/stl_iterator.h
libstdc++-v3/include/std/string_view
libstdc++-v3/include/std/version
libstdc++-v3/testsuite/23_containers/array/element_access/constexpr_c++17.cc [new file with mode: 0644]
libstdc++-v3/testsuite/23_containers/array/requirements/constexpr_iter.cc

index 4589039deb5969901e294c2373a3f8d725469eeb..ff8856fc0c3cf756b61de9365b704f3d145a1b34 100644 (file)
@@ -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>
 
index e9d90fa01f405e67c72ff34821c9a81af760f480..11dd9b0fd4ca87527f854331c21ac2caf5203fbc 100644 (file)
@@ -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)
index bca3af89836c784441b189a378df28fcecef3e90..4d90438e6be1540cc6f6f1771897ceb4ed28e203 100644 (file)
@@ -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
index fb0440d4e126b0d04eb412793aabd335f4640763..c54f6ffbb4c958ff775e3ea5eb60b4332464ddc7 100644 (file)
 #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
 # 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 (file)
index 0000000..dd69645
--- /dev/null
@@ -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) );
index 208078c3b5aa86d914eed1daaf09fe88e0afdad7..7ede36073e196cd859a87462a3345ca0e4b7580d 100644 (file)
@@ -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.
 //
 
 #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()
 {