variant (variant::operator=): Fix assignment on references.
authorTim Shen <timshen@google.com>
Thu, 22 Sep 2016 08:45:55 +0000 (08:45 +0000)
committerTim Shen <timshen@gcc.gnu.org>
Thu, 22 Sep 2016 08:45:55 +0000 (08:45 +0000)
* libstdc++-v3/include/std/variant (variant::operator=): Fix assignment
on references.
* libstdc++-v3/testsuite/20_util/variant/compile.cc: Add test.

From-SVN: r240343

libstdc++-v3/ChangeLog
libstdc++-v3/include/std/variant
libstdc++-v3/testsuite/20_util/variant/compile.cc

index 0de2044de14d18f9e33a04ee9243bcb7f4f6ea0f..ff984c37f0e0f949a740ee11c6bdf0ce69ef1408 100644 (file)
@@ -1,3 +1,9 @@
+2016-09-22  Tim Shen  <timshen@google.com>
+
+       * libstdc++-v3/include/std/variant (variant::operator=): Fix assignment
+       on references.
+       * libstdc++-v3/testsuite/20_util/variant/compile.cc: Add test.
+
 2016-09-22  Tim Shen  <timshen@google.com>
 
        PR libstdc++/77641
index 013884bb23ec17f0bd41f52e8f522963edcabcd0..1ad33fc5da0d03ce9869f3fad9bf8ff4a269b5a1 100644 (file)
@@ -1147,8 +1147,7 @@ namespace __variant
        {
          constexpr auto __index = __accepted_index<_Tp&&>;
          if (index() == __index)
-           *static_cast<__storage<__to_type<__index>>*>(this->_M_storage())
-             = forward<_Tp>(__rhs);
+           std::get<__index>(*this) = std::forward<_Tp>(__rhs);
          else
            this->emplace<__index>(forward<_Tp>(__rhs));
          __glibcxx_assert(holds_alternative<__accepted_type<_Tp&&>>(*this));
index 99f980a72db039e4bdf730cdfcfa2a33218e3120..a0a8d70ce871215f63778ad62f95cb943f80918f 100644 (file)
@@ -169,6 +169,12 @@ void copy_assign()
     variant<DefaultNoexcept> a;
     static_assert(!noexcept(a = a), "");
   }
+
+  {
+    float f1 = 1.0f, f2 = 2.0f;
+    std::variant<float&> v1(f1);
+    v1 = f2;
+  }
 }
 
 void move_assign()