]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libstdc++: Expand compile-time ranges tests for vector and basic_string.
authorTomasz Kamiński <tkaminsk@redhat.com>
Wed, 23 Jul 2025 09:33:22 +0000 (11:33 +0200)
committerTomasz Kamiński <tkaminsk@redhat.com>
Thu, 24 Jul 2025 13:13:46 +0000 (15:13 +0200)
This replaces most test_constexpr invocations with direct calls to
test_ranges(), which is also used for runtime tests.

SimpleAllocator was made constexpr to simplify this refactoring. Other
test allocators, like uneq_allocator (used in from_range constructor
tests), were not updated.

libstdc++-v3/ChangeLog:

* testsuite/21_strings/basic_string/cons/from_range.cc: Replace
test_constexpr with test_ranges inside static_assert.
* testsuite/21_strings/basic_string/modifiers/append/append_range.cc:
Likewise.
* testsuite/21_strings/basic_string/modifiers/assign/assign_range.cc:
Likewise.
* testsuite/21_strings/basic_string/modifiers/insert/insert_range.cc:
Likewise.
* testsuite/21_strings/basic_string/modifiers/replace/replace_with_range.cc:
Likewise.
* testsuite/23_containers/vector/bool/cons/from_range.cc: Likewise.
* testsuite/23_containers/vector/bool/modifiers/assign/assign_range.cc:
Likewise.
* testsuite/23_containers/vector/bool/modifiers/insert/insert_range.cc:
Likewise.
* testsuite/23_containers/vector/cons/from_range.cc: Likewise.
* testsuite/23_containers/vector/modifiers/assign/assign_range.cc:
Likewise.
* testsuite/23_containers/vector/modifiers/insert/insert_range.cc:
Likewise.
* testsuite/23_containers/vector/bool/modifiers/insert/append_range.cc:
Run full test_ranges instead of span-only in test_constexpr.
* testsuite/23_containers/vector/modifiers/append_range.cc:
Replace test_constexpr with calls to test_ranges and test_overlapping.
* testsuite/util/testsuite_allocator.h (__gnu_test::SimpleAllocator):
Declared member functions as constexpr.

14 files changed:
libstdc++-v3/testsuite/21_strings/basic_string/cons/from_range.cc
libstdc++-v3/testsuite/21_strings/basic_string/modifiers/append/append_range.cc
libstdc++-v3/testsuite/21_strings/basic_string/modifiers/assign/assign_range.cc
libstdc++-v3/testsuite/21_strings/basic_string/modifiers/insert/insert_range.cc
libstdc++-v3/testsuite/21_strings/basic_string/modifiers/replace/replace_with_range.cc
libstdc++-v3/testsuite/23_containers/vector/bool/cons/from_range.cc
libstdc++-v3/testsuite/23_containers/vector/bool/modifiers/assign/assign_range.cc
libstdc++-v3/testsuite/23_containers/vector/bool/modifiers/insert/append_range.cc
libstdc++-v3/testsuite/23_containers/vector/bool/modifiers/insert/insert_range.cc
libstdc++-v3/testsuite/23_containers/vector/cons/from_range.cc
libstdc++-v3/testsuite/23_containers/vector/modifiers/append_range.cc
libstdc++-v3/testsuite/23_containers/vector/modifiers/assign/assign_range.cc
libstdc++-v3/testsuite/23_containers/vector/modifiers/insert/insert_range.cc
libstdc++-v3/testsuite/util/testsuite_allocator.h

index 6331050309ce8519070ae7f1eef8a21a0f1c6195..df9e4c35cf116e0c60d6442b20ea7114df20d734 100644 (file)
@@ -73,16 +73,19 @@ do_test(Alloc alloc)
 }
 
 template<typename Range>
-void
+constexpr void
 do_test_a()
 {
   do_test<Range>(std::allocator<char>());
-  do_test<Range>(__gnu_test::uneq_allocator<char>(42));
   do_test<Range>(std::allocator<wchar_t>());
-  do_test<Range>(__gnu_test::uneq_allocator<wchar_t>(42));
+
+  if not consteval {
+    do_test<Range>(__gnu_test::uneq_allocator<char>(42));
+    do_test<Range>(__gnu_test::uneq_allocator<wchar_t>(42));
+  }
 }
 
-bool
+constexpr bool
 test_ranges()
 {
   using namespace __gnu_test;
@@ -101,9 +104,9 @@ test_ranges()
 
   // Not lvalue-convertible to char
   struct C {
-    C(char v) : val(v) { }
-    operator char() && { return val; }
-    bool operator==(char b) const { return b == val; }
+    constexpr C(char v) : val(v) { }
+    constexpr operator char() && { return val; }
+    constexpr bool operator==(char b) const { return b == val; }
     char val;
   };
   using rvalue_input_range = test_range<C, input_iterator_wrapper_rval>;
@@ -112,18 +115,10 @@ test_ranges()
   return true;
 }
 
-constexpr bool
-test_constexpr()
-{
-#if _GLIBCXX_USE_CXX11_ABI
-  // XXX: this doesn't test the non-forward_range code paths are constexpr.
-  do_test<std::string_view>(std::allocator<char>());
-#endif // _GLIBCXX_USE_CXX11_ABI
-  return true;
-}
-
 int main()
 {
   test_ranges();
-  static_assert( test_constexpr() );
+#if _GLIBCXX_USE_CXX11_ABI
+  static_assert( test_ranges() );
+#endif // _GLIBCXX_USE_CXX11_ABI
 }
index 6c0bc0cab1850db11c950fb57bd03f7399d0a886..984db3640f94d9d5fe615af2f4eeffecaa59fe28 100644 (file)
@@ -49,7 +49,7 @@ do_test()
 }
 
 template<typename Range>
-void
+constexpr void
 do_test_a()
 {
   do_test<Range, std::allocator<char>>();
@@ -58,7 +58,7 @@ do_test_a()
   do_test<Range, __gnu_test::SimpleAllocator<wchar_t>>();
 }
 
-bool
+constexpr bool
 test_ranges()
 {
   using namespace __gnu_test;
@@ -77,9 +77,9 @@ test_ranges()
 
   // Not lvalue-convertible to char
   struct C {
-    C(char v) : val(v) { }
-    operator char() && { return val; }
-    bool operator==(char b) const { return b == val; }
+    constexpr C(char v) : val(v) { }
+    constexpr operator char() && { return val; }
+    constexpr bool operator==(char b) const { return b == val; }
     char val;
   };
   using rvalue_input_range = test_range<C, input_iterator_wrapper_rval>;
@@ -107,19 +107,11 @@ test_overlapping()
   VERIFY( c == "1234abcd1234" );
 }
 
-constexpr bool
-test_constexpr()
-{
-#if _GLIBCXX_USE_CXX11_ABI
-  // XXX: this doesn't test the non-forward_range code paths are constexpr.
-  do_test<std::string_view, std::allocator<char>>();
-#endif // _GLIBCXX_USE_CXX11_ABI
-  return true;
-}
-
 int main()
 {
   test_ranges();
   test_overlapping();
-  static_assert( test_constexpr() );
+#if _GLIBCXX_USE_CXX11_ABI
+  static_assert( test_ranges() );
+#endif // _GLIBCXX_USE_CXX11_ABI
 }
index 310c8bc0003b0f496439ec3ae39e3209f22bc305..aa1b329a5511916f7e5c6c30762cb699b78e66ea 100644 (file)
@@ -41,7 +41,7 @@ do_test()
 }
 
 template<typename Range>
-void
+constexpr void
 do_test_a()
 {
   do_test<Range, std::allocator<char>>();
@@ -50,7 +50,7 @@ do_test_a()
   do_test<Range, __gnu_test::SimpleAllocator<wchar_t>>();
 }
 
-bool
+constexpr bool
 test_ranges()
 {
   using namespace __gnu_test;
@@ -69,9 +69,9 @@ test_ranges()
 
   // Not lvalue-convertible to char
   struct C {
-    C(char v) : val(v) { }
-    operator char() && { return val; }
-    bool operator==(char b) const { return b == val; }
+    constexpr C(char v) : val(v) { }
+    constexpr operator char() && { return val; }
+    constexpr bool operator==(char b) const { return b == val; }
     char val;
   };
   using rvalue_input_range = test_range<C, input_iterator_wrapper_rval>;
@@ -98,19 +98,11 @@ test_overlapping()
   VERIFY( c == "1234" );
 }
 
-constexpr bool
-test_constexpr()
-{
-#if _GLIBCXX_USE_CXX11_ABI
-  // XXX: this doesn't test the non-forward_range code paths are constexpr.
-  do_test<std::string_view, std::allocator<char>>();
-#endif // _GLIBCXX_USE_CXX11_ABI
-  return true;
-}
-
 int main()
 {
   test_ranges();
   test_overlapping();
-  static_assert( test_constexpr() );
+#if _GLIBCXX_USE_CXX11_ABI
+  static_assert( test_ranges() );
+#endif // _GLIBCXX_USE_CXX11_ABI
 }
index 4fead3245d1f30b9922a2eb7c7d2b9b510a82de1..c026fd4b8d81977476a53f1c72748f437184b578 100644 (file)
@@ -54,7 +54,7 @@ do_test()
 }
 
 template<typename Range>
-void
+constexpr void
 do_test_a()
 {
   do_test<Range, std::allocator<char>>();
@@ -63,7 +63,7 @@ do_test_a()
   do_test<Range, __gnu_test::SimpleAllocator<wchar_t>>();
 }
 
-bool
+constexpr bool
 test_ranges()
 {
   using namespace __gnu_test;
@@ -82,9 +82,9 @@ test_ranges()
 
   // Not lvalue-convertible to char
   struct C {
-    C(char v) : val(v) { }
-    operator char() && { return val; }
-    bool operator==(char b) const { return b == val; }
+    constexpr C(char v) : val(v) { }
+    constexpr operator char() && { return val; }
+    constexpr bool operator==(char b) const { return b == val; }
     char val;
   };
   using rvalue_input_range = test_range<C, input_iterator_wrapper_rval>;
@@ -112,19 +112,11 @@ test_overlapping()
   VERIFY( c == "12123434abcd" );
 }
 
-constexpr bool
-test_constexpr()
-{
-#if _GLIBCXX_USE_CXX11_ABI
-  // XXX: this doesn't test the non-forward_range code paths are constexpr.
-  do_test<std::string_view, std::allocator<char>>();
-#endif // _GLIBCXX_USE_CXX11_ABI
-  return true;
-}
-
 int main()
 {
   test_ranges();
   test_overlapping();
-  static_assert( test_constexpr() );
+#if _GLIBCXX_USE_CXX11_ABI
+  static_assert( test_ranges() );
+#endif // _GLIBCXX_USE_CXX11_ABI
 }
index 9acf11ab5bdf907f66e426c515e2c7e30c74b296..4c6bba5993ef386a238dff6f6586a1137984afe5 100644 (file)
@@ -54,7 +54,7 @@ do_test()
 }
 
 template<typename Range>
-void
+constexpr void
 do_test_a()
 {
   do_test<Range, std::allocator<char>>();
@@ -63,7 +63,7 @@ do_test_a()
   do_test<Range, __gnu_test::SimpleAllocator<wchar_t>>();
 }
 
-bool
+constexpr bool
 test_ranges()
 {
   using namespace __gnu_test;
@@ -82,9 +82,9 @@ test_ranges()
 
   // Not lvalue-convertible to char
   struct C {
-    C(char v) : val(v) { }
-    operator char() && { return val; }
-    bool operator==(char b) const { return b == val; }
+    constexpr C(char v) : val(v) { }
+    constexpr operator char() && { return val; }
+    constexpr bool operator==(char b) const { return b == val; }
     char val;
   };
   using rvalue_input_range = test_range<C, input_iterator_wrapper_rval>;
@@ -115,19 +115,11 @@ test_overlapping()
   VERIFY( c == "12123434abcd" );
 }
 
-constexpr bool
-test_constexpr()
-{
-#if _GLIBCXX_USE_CXX11_ABI
-  // XXX: this doesn't test the non-forward_range code paths are constexpr.
-  do_test<std::string_view, std::allocator<char>>();
-#endif // _GLIBCXX_USE_CXX11_ABI
-  return true;
-}
-
 int main()
 {
   test_ranges();
   test_overlapping();
-  static_assert( test_constexpr() );
+#if _GLIBCXX_USE_CXX11_ABI
+  static_assert( test_ranges() );
+#endif // _GLIBCXX_USE_CXX11_ABI
 }
index 339c06bd70e9cb6b4cd274af691e5d55b36f73b2..516d888b977a5d18cb78cc4a4a6679ea330e808a 100644 (file)
@@ -42,14 +42,16 @@ do_test(Alloc alloc)
 }
 
 template<typename Range>
-void
+constexpr void
 do_test_a()
 {
   do_test<Range>(std::allocator<bool>());
-  do_test<Range>(__gnu_test::uneq_allocator<bool>(42));
+  if not consteval {
+    do_test<Range>(__gnu_test::uneq_allocator<bool>(42));
+  }
 }
 
-bool
+constexpr bool
 test_ranges()
 {
   using namespace __gnu_test;
@@ -71,9 +73,9 @@ test_ranges()
 
   // Not lvalue-convertible to bool
   struct C {
-    C(bool v) : val(v) { }
-    operator bool() && { return val; }
-    bool operator==(bool b) const { return b == val; }
+    constexpr C(bool v) : val(v) { }
+    constexpr operator bool() && { return val; }
+    constexpr bool operator==(bool b) const { return b == val; }
     bool val;
   };
   using rvalue_input_range = test_range<C, input_iterator_wrapper_rval>;
@@ -82,16 +84,8 @@ test_ranges()
   return true;
 }
 
-constexpr bool
-test_constexpr()
-{
-  // XXX: this doesn't test the non-forward_range code paths are constexpr.
-  do_test<std::span<bool>>(std::allocator<bool>());
-  return true;
-}
-
 int main()
 {
   test_ranges();
-  static_assert( test_constexpr() );
+  static_assert( test_ranges() );
 }
index 7e58700ff2bb20a94ea812a0740c678ea424a662..ced7efebc7cb13086d7ace845e68a67edd89e7c5 100644 (file)
@@ -59,14 +59,14 @@ do_test()
 }
 
 template<typename Range>
-void
+constexpr void
 do_test_a()
 {
   do_test<Range, std::allocator<bool>>();
   do_test<Range, __gnu_test::SimpleAllocator<bool>>();
 }
 
-bool
+constexpr bool
 test_ranges()
 {
   using namespace __gnu_test;
@@ -88,9 +88,9 @@ test_ranges()
 
   // Not lvalue-convertible to bool
   struct C {
-    C(bool v) : val(v) { }
-    operator bool() && { return val; }
-    bool operator==(bool b) const { return b == val; }
+    constexpr C(bool v) : val(v) { }
+    constexpr operator bool() && { return val; }
+    constexpr bool operator==(bool b) const { return b == val; }
     bool val;
   };
   using rvalue_input_range = test_range<C, input_iterator_wrapper_rval>;
@@ -99,16 +99,8 @@ test_ranges()
   return true;
 }
 
-constexpr bool
-test_constexpr()
-{
-  // XXX: this doesn't test the non-forward_range code paths are constexpr.
-  do_test<std::span<short>, std::allocator<bool>>();
-  return true;
-}
-
 int main()
 {
   test_ranges();
-  static_assert( test_constexpr() );
+  static_assert( test_ranges() );
 }
index 43a698f65c412ee955deea6240ac4f617e1ffadc..c2e218653a8284222e4c1ad42565450aa85b00cf 100644 (file)
@@ -38,14 +38,14 @@ do_test()
 }
 
 template<typename Range>
-void
+constexpr void
 do_test_a()
 {
   do_test<Range, std::allocator<bool>>();
   do_test<Range, __gnu_test::SimpleAllocator<bool>>();
 }
 
-bool
+constexpr bool
 test_ranges()
 {
   using namespace __gnu_test;
@@ -67,9 +67,9 @@ test_ranges()
 
   // Not lvalue-convertible to bool
   struct C {
-    C(bool v) : val(v) { }
-    operator bool() && { return val; }
-    bool operator==(bool b) const { return b == val; }
+    constexpr C(bool v) : val(v) { }
+    constexpr operator bool() && { return val; }
+    constexpr bool operator==(bool b) const { return b == val; }
     bool val;
   };
   using rvalue_input_range = test_range<C, input_iterator_wrapper_rval>;
@@ -81,8 +81,7 @@ test_ranges()
 constexpr bool
 test_constexpr()
 {
-  // XXX: this doesn't test the non-forward_range code paths are constexpr.
-  do_test<std::span<short>, std::allocator<bool>>();
+  test_ranges();
 
   // Some basic tests for overlapping ranges in constant expressions.
   using I = std::vector<bool>::iterator;
index 5c65610667d5066d44189083ccbc770e95c61a55..2ec91b07ce78b3f8ac823bf20ed3b1bc160c565d 100644 (file)
@@ -55,14 +55,14 @@ do_test()
 }
 
 template<typename Range>
-void
+constexpr void
 do_test_a()
 {
   do_test<Range, std::allocator<bool>>();
   do_test<Range, __gnu_test::SimpleAllocator<bool>>();
 }
 
-bool
+constexpr bool
 test_ranges()
 {
   using namespace __gnu_test;
@@ -84,9 +84,9 @@ test_ranges()
 
   // Not lvalue-convertible to bool
   struct C {
-    C(bool v) : val(v) { }
-    operator bool() && { return val; }
-    bool operator==(bool b) const { return b == val; }
+    constexpr C(bool v) : val(v) { }
+    constexpr operator bool() && { return val; }
+    constexpr bool operator==(bool b) const { return b == val; }
     bool val;
   };
   using rvalue_input_range = test_range<C, input_iterator_wrapper_rval>;
@@ -95,16 +95,8 @@ test_ranges()
   return true;
 }
 
-constexpr bool
-test_constexpr()
-{
-  // XXX: this doesn't test the non-forward_range code paths are constexpr.
-  do_test<std::span<bool>, std::allocator<bool>>();
-  return true;
-}
-
 int main()
 {
   test_ranges();
-  static_assert( test_constexpr() );
+  static_assert( test_ranges() );
 }
index 3784b9cd66ad0367dd70f6408c83666b701500c0..be3e69928903026e7b473a6fb1a0b5537bdbba03 100644 (file)
@@ -58,14 +58,16 @@ do_test(Alloc alloc)
 }
 
 template<typename Range>
-void
+constexpr void
 do_test_a()
 {
   do_test<Range>(std::allocator<int>());
-  do_test<Range>(__gnu_test::uneq_allocator<int>(42));
+  if not consteval {
+    do_test<Range>(__gnu_test::uneq_allocator<int>(42));
+  }
 }
 
-bool
+constexpr bool
 test_ranges()
 {
   using namespace __gnu_test;
@@ -87,9 +89,9 @@ test_ranges()
 
   // Not lvalue-convertible to int
   struct C {
-    C(int v) : val(v) { }
-    operator int() && { return val; }
-    bool operator==(int b) const { return b == val; }
+    constexpr C(int v) : val(v) { }
+    constexpr operator int() && { return val; }
+    constexpr bool operator==(int b) const { return b == val; }
     int val;
   };
   using rvalue_input_range = test_range<C, input_iterator_wrapper_rval>;
@@ -98,14 +100,6 @@ test_ranges()
   return true;
 }
 
-constexpr bool
-test_constexpr()
-{
-  // XXX: this doesn't test the non-forward_range code paths are constexpr.
-  do_test<std::span<short>>(std::allocator<int>());
-  return true;
-}
-
 void
 test_pr120367()
 {
@@ -130,6 +124,6 @@ test_pr120367()
 int main()
 {
   test_ranges();
-  static_assert( test_constexpr() );
+  static_assert( test_ranges() );
   test_pr120367();
 }
index be097e2b13101d7cdf596e7aa659485bead32e30..f5b21df9360d065abde6e9428f9bd9ed1e72eaea 100644 (file)
@@ -42,14 +42,14 @@ do_test()
 }
 
 template<typename Range>
-void
+constexpr void
 do_test_a()
 {
   do_test<Range, std::allocator<int>>();
   do_test<Range, __gnu_test::SimpleAllocator<int>>();
 }
 
-bool
+constexpr bool
 test_ranges()
 {
   using namespace __gnu_test;
@@ -71,9 +71,9 @@ test_ranges()
 
   // Not lvalue-convertible to int
   struct C {
-    C(int v) : val(v) { }
-    operator int() && { return val; }
-    bool operator==(int b) const { return b == val; }
+    constexpr C(int v) : val(v) { }
+    constexpr operator int() && { return val; }
+    constexpr bool operator==(int b) const { return b == val; }
     int val;
   };
   using rvalue_input_range = test_range<C, input_iterator_wrapper_rval>;
@@ -82,7 +82,7 @@ test_ranges()
   return true;
 }
 
-void
+constexpr void
 test_overlapping()
 {
   using __gnu_test::test_input_range;
@@ -199,64 +199,14 @@ test_overlapping()
   }
 }
 
-constexpr bool
-test_constexpr()
+int main()
 {
-  // XXX: this doesn't test the non-forward_range code paths are constexpr.
-  do_test<std::span<short>, std::allocator<int>>();
-
-  // Some basic tests for overlapping ranges in constant expressions.
-  struct InputRange
-  {
-    struct Sent { const void* end; };
-
-    struct Iter
-    {
-      using value_type = int;
-      using difference_type = int;
-      constexpr explicit Iter(int* p) : ptr(p) { }
-      constexpr Iter& operator++() { ++ptr; return *this; }
-      constexpr Iter operator++(int) { auto i = *this; ++ptr; return i; }
-      constexpr int operator*() const { return *ptr; }
-      constexpr bool operator==(const Iter&) const = default;
-      constexpr bool operator==(const Sent& s) const { return ptr == s.end; }
-      int* ptr;
-    };
-
-    Iter iter;
-    Sent sent;
-
-    constexpr InputRange(int* f, int* l) : iter{f}, sent{l} { }
-    constexpr Iter begin() const { return iter; }
-    constexpr Sent end() const { return sent; }
+  auto test_all = [] {
+    test_ranges();
+    test_overlapping();
+    return true;
   };
-  static_assert( std::ranges::input_range<InputRange> );
-  static_assert( ! std::ranges::forward_range<InputRange> );
-
-  std::vector<int> vec(5);
-
-  // Test overlapping input ranges
-  vec.resize(vec.capacity());
-  vec.append_range(InputRange(vec.data(), vec.data() + 3)); // no capacity
-  vec.reserve(vec.capacity() + 2);
-  vec.append_range(InputRange(vec.data(), vec.data() + 4)); // some capacity
-  vec.reserve(vec.capacity() + 6);
-  vec.append_range(InputRange(vec.data(), vec.data() + 5)); // enough capacity
-
-  // Test overlapping forward ranges
-  vec.resize(vec.capacity());
-  vec.append_range(std::span<int>(vec));               // no capacity
-  vec.reserve(vec.size() + 2);
-  vec.append_range(std::span<int>(vec).subspan(1, 4)); // some capacity
-  vec.reserve(vec.size() + 6);
-  vec.append_range(std::span<int>(vec).subspan(1, 5)); // enough capacity
 
-  return true;
-}
-
-int main()
-{
-  test_ranges();
-  test_overlapping();
-  static_assert( test_constexpr() );
+  test_all();
+  static_assert( test_all() );
 }
index db3b06cfbc06a02f8d63d37d11324164ef4f75b8..26d33bcf9811d6001d1ba45e0850f1f429f112ab 100644 (file)
@@ -63,14 +63,14 @@ do_test()
 }
 
 template<typename Range>
-void
+constexpr void
 do_test_a()
 {
   do_test<Range, std::allocator<int>>();
   do_test<Range, __gnu_test::SimpleAllocator<int>>();
 }
 
-bool
+constexpr bool
 test_ranges()
 {
   using namespace __gnu_test;
@@ -92,9 +92,9 @@ test_ranges()
 
   // Not lvalue-convertible to int
   struct C {
-    C(int v) : val(v) { }
-    operator int() && { return val; }
-    bool operator==(int b) const { return b == val; }
+    constexpr C(int v) : val(v) { }
+    constexpr operator int() && { return val; }
+    constexpr bool operator==(int b) const { return b == val; }
     int val;
   };
   using rvalue_input_range = test_range<C, input_iterator_wrapper_rval>;
@@ -103,16 +103,8 @@ test_ranges()
   return true;
 }
 
-constexpr bool
-test_constexpr()
-{
-  // XXX: this doesn't test the non-forward_range code paths are constexpr.
-  do_test<std::span<short>, std::allocator<int>>();
-  return true;
-}
-
 int main()
 {
   test_ranges();
-  static_assert( test_constexpr() );
+  static_assert( test_ranges() );
 }
index 5907143512676a8cd66596f1543a68a60a255ecc..506bebbe519eea1c856cde0f90dd1fec28d9500b 100644 (file)
@@ -59,14 +59,14 @@ do_test()
 }
 
 template<typename Range>
-void
+constexpr void
 do_test_a()
 {
   do_test<Range, std::allocator<int>>();
   do_test<Range, __gnu_test::SimpleAllocator<int>>();
 }
 
-bool
+constexpr bool
 test_ranges()
 {
   using namespace __gnu_test;
@@ -88,9 +88,9 @@ test_ranges()
 
   // Not lvalue-convertible to int
   struct C {
-    C(int v) : val(v) { }
-    operator int() && { return val; }
-    bool operator==(int b) const { return b == val; }
+    constexpr C(int v) : val(v) { }
+    constexpr operator int() && { return val; }
+    constexpr bool operator==(int b) const { return b == val; }
     int val;
   };
   using rvalue_input_range = test_range<C, input_iterator_wrapper_rval>;
@@ -99,16 +99,8 @@ test_ranges()
   return true;
 }
 
-constexpr bool
-test_constexpr()
-{
-  // XXX: this doesn't test the non-forward_range code paths are constexpr.
-  do_test<std::span<short>, std::allocator<int>>();
-  return true;
-}
-
 int main()
 {
   test_ranges();
-  static_assert( test_constexpr() );
+  static_assert( test_ranges() );
 }
index e5ffad2ba5875de9bed447903c62083bcb5c9089..ee9575266a009c3aa5749baac2f85792f8213b66 100644 (file)
@@ -517,19 +517,24 @@ namespace __gnu_test
       constexpr SimpleAllocator() noexcept { }
 
       template <class T>
+       constexpr
         SimpleAllocator(const SimpleAllocator<T>&) { }
 
+      _GLIBCXX20_CONSTEXPR
       Tp *allocate(std::size_t n)
       { return std::allocator<Tp>().allocate(n); }
 
+      _GLIBCXX20_CONSTEXPR
       void deallocate(Tp *p, std::size_t n)
       { std::allocator<Tp>().deallocate(p, n); }
     };
 
   template <class T, class U>
+    constexpr
     bool operator==(const SimpleAllocator<T>&, const SimpleAllocator<U>&)
     { return true; }
   template <class T, class U>
+    constexpr
     bool operator!=(const SimpleAllocator<T>&, const SimpleAllocator<U>&)
     { return false; }