[libcxx-commits] [PATCH] D62928: Constrain function assignment operator (2574)

Zoe Carver via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Wed Jun 5 12:55:40 PDT 2019


zoecarver created this revision.
zoecarver added reviewers: mclow.lists, ldionne, EricWF.
Herald added subscribers: libcxx-commits, dexonsmith.
zoecarver marked an inline comment as done.
zoecarver added inline comments.


================
Comment at: test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/F_assign.pass.cpp:128
+        using F1 = std::function<int(int, int)>;
+        using F2 = std::function<A  (int, int)>;
+        static_assert(!std::is_assignable<F1&, F2&&>::value, "");
----------------
Is it okay to allow assignment of functions with return types that are convertible to each other? The issue says:

> Callable (C++14 ยง20.9.11.2) for argument types ArgTypes... and return type R.


This patch fixes issue 2574 <https://cplusplus.github.io/LWG/issue2574>.


Repository:
  rCXX libc++

https://reviews.llvm.org/D62928

Files:
  include/functional
  test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/F_assign.pass.cpp
  www/cxx1z_status.html


Index: www/cxx1z_status.html
===================================================================
--- www/cxx1z_status.html
+++ www/cxx1z_status.html
@@ -299,7 +299,7 @@
 	<tr><td><a href="https://wg21.link/LWG2566">2566</a></td><td>Requirements on the first template parameter of container adaptors</td><td>Jacksonville</td><td>Complete</td></tr>
 	<tr><td><a href="https://wg21.link/LWG2571">2571</a></td><td>§[map.modifiers]/2 imposes nonsensical requirement on <tt>insert(InputIterator, InputIterator)</tt></td><td>Jacksonville</td><td>Complete</td></tr>
 	<tr><td><a href="https://wg21.link/LWG2572">2572</a></td><td>The remarks for <tt>shared_ptr::operator*</tt> should apply to <i>cv</i>-qualified <tt>void</tt> as well</td><td>Jacksonville</td><td>Complete</td></tr>
-	<tr><td><a href="https://wg21.link/LWG2574">2574</a></td><td>[fund.ts.v2] <tt>std::experimental::function::operator=(F&&)</tt> should be constrained</td><td>Jacksonville</td><td></td></tr>
+	<tr><td><a href="https://wg21.link/LWG2574">2574</a></td><td>[fund.ts.v2] <tt>std::experimental::function::operator=(F&&)</tt> should be constrained</td><td>Jacksonville</td><td>Complete</td></tr>
 	<tr><td><a href="https://wg21.link/LWG2575">2575</a></td><td>[fund.ts.v2] <tt>experimental::function::assign</tt> should be removed</td><td>Jacksonville</td><td></td></tr>
 	<tr><td><a href="https://wg21.link/LWG2576">2576</a></td><td><tt>istream_iterator</tt> and <tt>ostream_iterator</tt> should use <tt>std::addressof</tt></td><td>Jacksonville</td><td>Complete</td></tr>
 	<tr><td><a href="https://wg21.link/LWG2577">2577</a></td><td><tt>{shared,unique}_lock</tt> should use <tt>std::addressof</tt></td><td>Jacksonville</td><td>Complete</td></tr>
Index: test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/F_assign.pass.cpp
===================================================================
--- test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/F_assign.pass.cpp
+++ test/std/utilities/function.objects/func.wrap/func.wrap.func/func.wrap.func.con/F_assign.pass.cpp
@@ -114,6 +114,25 @@
         static_assert(!std::is_assignable<Fn&, RValueCallable&>::value, "");
         static_assert(!std::is_assignable<Fn&, RValueCallable>::value, "");
     }
+    {
+        using Fn = std::function<void(int, int, int)>;
+        static_assert(std::is_assignable<Fn&, Fn&&>::value, "");
+    }
+    {
+        using F1 = std::function<void(int, int)>;
+        using F2 = std::function<void(int, int, int)>;
+        static_assert(!std::is_assignable<F1&, F2&&>::value, "");
+    }
+    {
+        using F1 = std::function<int(int, int)>;
+        using F2 = std::function<A  (int, int)>;
+        static_assert(!std::is_assignable<F1&, F2&&>::value, "");
+    }
+    {
+        using F1 = std::function<void(int, int)>;
+        using F2 = std::function<void(int, int)&&>;
+        static_assert(!std::is_assignable<F1&, F2&&>::value, "");
+    }
 #endif
 
   return 0;
Index: include/functional
===================================================================
--- include/functional
+++ include/functional
@@ -2228,7 +2228,7 @@
     function& operator=(const function&);
     function& operator=(function&&) _NOEXCEPT;
     function& operator=(nullptr_t) _NOEXCEPT;
-    template<class _Fp, class = _EnableIfCallable<_Fp>>
+    template<class _Fp, class = _EnableIfCallable<typename decay<_Fp>::type&>>
     function& operator=(_Fp&&);
 
     ~function();


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D62928.203232.patch
Type: text/x-patch
Size: 3500 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20190605/941b6282/attachment.bin>


More information about the libcxx-commits mailing list