diff mbox

[v3] Fix the constraints for any's assignment operator template to properly reject assignment from a non-copyable lvalue.

Message ID CAFk2RUZ5s+BoUaqHLE6p6DRfDztNuBWzvu6tvoK+qF4d5f1D4w@mail.gmail.com
State New
Headers show

Commit Message

Ville Voutilainen July 14, 2016, 5:27 p.m. UTC
Tested on Linux-x64.

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.

Comments

Jonathan Wakely July 15, 2016, 7:40 a.m. UTC | #1
On 14/07/16 20:27 +0300, Ville Voutilainen wrote:
>    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.

OK for trunk, thanks.
diff mbox

Patch

diff --git a/libstdc++-v3/include/std/any b/libstdc++-v3/include/std/any
index 54882d7..4add118 100644
--- a/libstdc++-v3/include/std/any
+++ b/libstdc++-v3/include/std/any
@@ -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));
diff --git a/libstdc++-v3/testsuite/20_util/any/requirements.cc b/libstdc++-v3/testsuite/20_util/any/requirements.cc
index 67e4253..f33cd67 100644
--- a/libstdc++-v3/testsuite/20_util/any/requirements.cc
+++ b/libstdc++-v3/testsuite/20_util/any/requirements.cc
@@ -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);