libstdc++: Update (and revert) value of __cpp_lib_array_constexpr
authorJonathan Wakely <jwakely@redhat.com>
Wed, 22 Apr 2020 21:54:35 +0000 (22:54 +0100)
committerJonathan Wakely <jwakely@redhat.com>
Wed, 22 Apr 2020 21:54:35 +0000 (22:54 +0100)
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.

libstdc++-v3/ChangeLog
libstdc++-v3/include/bits/stl_iterator.h
libstdc++-v3/include/std/version
libstdc++-v3/testsuite/23_containers/array/comparison_operators/constexpr.cc
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_fill.cc
libstdc++-v3/testsuite/23_containers/array/requirements/constexpr_iter.cc

index 4fec7b2..cce2549 100644 (file)
@@ -1,5 +1,18 @@
 2020-04-22  Jonathan Wakely  <jwakely@redhat.com>
 
+       * 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
index 652f51c..d7e85b8 100644 (file)
 # include <type_traits>
 #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
index 85bc142..57a0525 100644 (file)
 #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
 #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
index fd6029b..0f3a415 100644 (file)
 
 #include <array>
 
+#ifndef __cpp_lib_array_constexpr
+# error "Feature test macro for array constexpr is missing in <array>"
+#elif __cpp_lib_array_constexpr < 201806L
+# error "Feature test macro for array constexpr has wrong value in <array>"
+#endif
+
 constexpr std::array<int, 3> a1{{1, 2, 3}};
 constexpr std::array<int, 3> a2{{4, 5, 6}};
 constexpr std::array<int, 3> 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 (file)
index 0000000..56d1cf2
--- /dev/null
@@ -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
+// <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>"
+#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<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 c7f9dd7..bb69634 100644 (file)
 
 #include <array>
 
+#ifndef __cpp_lib_array_constexpr
+# error "Feature test macro for array constexpr is missing in <array>"
+#elif __cpp_lib_array_constexpr < 201811L
+# error "Feature test macro for array constexpr has wrong value in <array>"
+#endif
+
 constexpr bool
 test_array()
 {
index f3f9ae6..a119937 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-2020 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 < 201603L
+# error "Feature test macro for array constexpr has wrong value in <array>"
+#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()
 {