]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libstdc++: Make copyable-box completely constexpr (LWG 3572)
authorJonathan Wakely <jwakely@redhat.com>
Tue, 11 Jan 2022 14:11:46 +0000 (14:11 +0000)
committerJonathan Wakely <jwakely@redhat.com>
Tue, 11 Jan 2022 15:17:26 +0000 (15:17 +0000)
This LWG issue was approved at the October 2021 plenary and can be
implemented now that std::optional is fully constexpr.

libstdc++-v3/ChangeLog:

* include/std/ranges (ranges::__detail::__box): Add constexpr to
assignment operators (LWG 3572).
* testsuite/std/ranges/adaptors/filter.cc: Check assignment of a
view that uses copyable-box.

libstdc++-v3/include/std/ranges
libstdc++-v3/testsuite/std/ranges/adaptors/filter.cc

index c90d33c89fb7e23a8ec58c640c70327a18755e72..780a3633417eb8a50f9339cdca9c2f46c06de154 100644 (file)
@@ -109,7 +109,8 @@ namespace ranges
 
        // _GLIBCXX_RESOLVE_LIB_DEFECTS
        // 3477. Simplify constraints for semiregular-box
-       __box&
+       // 3572. copyable-box should be fully constexpr
+       constexpr __box&
        operator=(const __box& __that)
        noexcept(is_nothrow_copy_constructible_v<_Tp>)
        requires (!copyable<_Tp>)
@@ -124,7 +125,7 @@ namespace ranges
          return *this;
        }
 
-       __box&
+       constexpr __box&
        operator=(__box&& __that)
        noexcept(is_nothrow_move_constructible_v<_Tp>)
        requires (!movable<_Tp>)
index b8d081e1d5e6dab1144909b3468f66e3293873d9..ed5a01ca595370cf4011b1e5038f5524c6b0f670 100644 (file)
@@ -140,6 +140,33 @@ test06()
   static_assert(!requires { views::all | filter; });
 }
 
+constexpr bool
+test07()
+{
+  struct Pred
+  {
+    constexpr Pred() { }
+    constexpr Pred(const Pred&) { }
+    constexpr Pred(Pred&&) { }
+    // These make it non-copyable, so non-copyable-box<Pred> will provide
+    // assignment.
+    Pred& operator=(const Pred&) = delete;
+    Pred& operator=(Pred&&) = delete;
+
+    bool operator()(int i) const { return i < 10; }
+  };
+
+  int i = 0;
+  ranges::filter_view v(views::single(i), Pred{});
+  // LWG 3572. copyable-box should be fully constexpr
+  v = v;
+  v = std::move(v);
+
+  return true;
+}
+
+static_assert( test07() );
+
 int
 main()
 {
@@ -150,4 +177,5 @@ main()
   test05<forward_iterator_wrapper>();
   test05<random_access_iterator_wrapper>();
   test06();
+  test07();
 }