re PR libstdc++/79513 (std::visit doesn't handle references)
authorTim Shen <timshen@google.com>
Wed, 15 Feb 2017 07:38:20 +0000 (07:38 +0000)
committerTim Shen <timshen@gcc.gnu.org>
Wed, 15 Feb 2017 07:38:20 +0000 (07:38 +0000)
PR libstdc++/79513
* include/std/variant (visit()): Forward variant types to the return
type detection code.
* testsuite/20_util/variant/compile.cc: Add test cases.

From-SVN: r245474

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

index e88fe2dcd4cd93e964a66ad9cb7307290e59ef4c..ec6e601c1ef42eff3c25ab38e018349829f84e0d 100644 (file)
@@ -1,3 +1,10 @@
+2017-02-15  Tim Shen  <timshen@google.com>
+
+       PR libstdc++/79513
+       * include/std/variant (visit()): Forward variant types to the return
+       type detection code.
+       * testsuite/20_util/variant/compile.cc: Add test cases.
+
 2017-02-13  H.J. Lu  <hongjiu.lu@intel.com>
 
        PR libstdc++/79348
index c5138e56803f6c4eebd402f58f82892e9b25195d..866c4c40a618b16e2d48ae1a05dca745d0f1eef0 100644 (file)
@@ -1263,7 +1263,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
        __throw_bad_variant_access("Unexpected index");
 
       using _Result_type =
-       decltype(std::forward<_Visitor>(__visitor)(get<0>(__variants)...));
+       decltype(std::forward<_Visitor>(__visitor)(
+           get<0>(std::forward<_Variants>(__variants))...));
 
       constexpr auto& __vtable = __detail::__variant::__gen_vtable<
        _Result_type, _Visitor&&, _Variants&&...>::_S_vtable;
index 65f4326c3975326fc35c2efef4bc1878973a6fc4..3bf9d5bfba3b18a794b7bffa2922f8b3574a306b 100644 (file)
@@ -291,6 +291,12 @@ void test_visit()
     };
     static_assert(visit(Visitor(), variant<int, nonliteral>(0)), "");
   }
+  // PR libstdc++/79513
+  {
+    std::variant<int> v [[gnu::unused]] (5);
+    std::visit([](int&){}, v);
+    std::visit([](int&&){}, std::move(v));
+  }
 }
 
 void test_constexpr()