libstdc++: Simplify constraints for std::any construction [PR104242]
authorJonathan Wakely <jwakely@redhat.com>
Fri, 18 Mar 2022 13:10:01 +0000 (13:10 +0000)
committerJonathan Wakely <jwakely@redhat.com>
Fri, 18 Mar 2022 15:40:03 +0000 (15:40 +0000)
Partially revert r12-4190-g6da36b7d0e43b6f9281c65c19a025d4888a25b2d
because using __and_<..., is_copy_constructible<T>> when T is incomplete
results in an error about deriving from is_copy_constructible<T> when
that is incomplete. I don't know how to fix that, so this simply
restores the previous constraint which worked in this case (even though
I think it's technically undefined to use is_copy_constructible<T> with
incomplete T). This doesn't restore exactly what we had before, but uses
the is_copy_constructible_v and __is_in_place_type_v variable templates
instead of the ::value member.

libstdc++-v3/ChangeLog:

PR libstdc++/104242
* include/std/any (any(T&&)): Revert change to constraints.
* testsuite/20_util/any/cons/104242.cc: New test.

libstdc++-v3/include/std/any
libstdc++-v3/testsuite/20_util/any/cons/104242.cc [new file with mode: 0644]

index bdad762..a6770e8 100644 (file)
@@ -185,8 +185,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
     /// Construct with a copy of @p __value as the contained object.
     template <typename _Tp, typename _VTp = _Decay_if_not_any<_Tp>,
              typename _Mgr = _Manager<_VTp>,
-             typename = _Require<__not_<__is_in_place_type<_VTp>>,
-                                 is_copy_constructible<_VTp>>>
+             enable_if_t<is_copy_constructible_v<_VTp>
+                         && !__is_in_place_type_v<_VTp>, bool> = true>
       any(_Tp&& __value)
       : _M_manager(&_Mgr::_S_manage)
       {
diff --git a/libstdc++-v3/testsuite/20_util/any/cons/104242.cc b/libstdc++-v3/testsuite/20_util/any/cons/104242.cc
new file mode 100644 (file)
index 0000000..8d5868b
--- /dev/null
@@ -0,0 +1,12 @@
+// { dg-do compile { target c++17 } }
+
+// PR libstdc++/104242 - Class with constructor from std::any is not copyable
+
+#include <any>
+#include <type_traits>
+
+struct A {
+    A(const A&) = default;
+    explicit A(std::any value);
+};
+static_assert(std::is_copy_constructible_v<A>);