Fix the constraints for any's assignment operator template to properly
authorVille Voutilainen <ville.voutilainen@gmail.com>
Fri, 15 Jul 2016 07:44:22 +0000 (10:44 +0300)
committerVille Voutilainen <ville@gcc.gnu.org>
Fri, 15 Jul 2016 07:44:22 +0000 (10:44 +0300)
reject assignment from a non-copyable lvalue.

From-SVN: r238365

libstdc++-v3/ChangeLog
libstdc++-v3/include/std/any
libstdc++-v3/testsuite/20_util/any/requirements.cc

index 68086139cbd9a31ee5e4c052c1dbb3d7cdc2d7d1..2386300807b252b7d02fd3e1b0fb1d30fa819ef2 100644 (file)
@@ -1,3 +1,12 @@
+2016-07-14  Ville Voutilainen  <ville.voutilainen@gmail.com>
+
+       Fix the constraints for any's assignment operator template to properly
+       reject assignment from a non-copyable lvalue.
+       * include/std/any (operator=(_ValueType&&)): Constrain the decayed
+       type for is_copy_constructible,
+       * testsuite/20_util/any/requirements.cc: Add a test for
+       non-copyable lvalues.
+
 2016-07-14  Jonathan Wakely  <jwakely@redhat.com>
 
        * include/experimental/functional: Include <parallel/algorithm> in
index 54882d797e20414655ce3c1c299db73921bbcd9a..4add1186923f8a87a911fcfb680d65841672d34b 100644 (file)
@@ -238,9 +238,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
     }
 
     /// Store a copy of @p __rhs as the contained object.
-    template<typename _ValueType>
-    enable_if_t<__and_<__not_<is_same<any, decay_t<_ValueType>>>,
-                      is_copy_constructible<_ValueType>>::value, any&>
+    template<typename _ValueType,
+            typename _Tp = _Decay<_ValueType>>
+    enable_if_t<is_copy_constructible<_Tp>::value, any&>
       operator=(_ValueType&& __rhs)
       {
        *this = any(std::forward<_ValueType>(__rhs));
index 67e4253c557b16459a2a4867ffb41f5db1db5cfd..f33cd67ffe6391e3a5127c51d24e07a741ddb12f 100644 (file)
@@ -30,4 +30,7 @@ static_assert(std::is_assignable<any&, int>::value);
 static_assert(!std::is_assignable<any&, unique_ptr<int>>::value);
 static_assert(std::is_constructible<any, int>::value);
 static_assert(!std::is_constructible<any, unique_ptr<int>>::value);
-
+static_assert(!std::is_assignable<any&, const unique_ptr<int>&>::value);
+static_assert(!std::is_constructible<any&, const unique_ptr<int>&>::value);
+static_assert(!std::is_assignable<any&, unique_ptr<int>&>::value);
+static_assert(!std::is_constructible<any&, unique_ptr<int>&>::value);