From 7d5abe42c27ca37bc9739f80e5f0f255206fed4f Mon Sep 17 00:00:00 2001 From: Tim Shen Date: Wed, 15 Feb 2017 07:38:20 +0000 Subject: [PATCH] re PR libstdc++/79513 (std::visit doesn't handle references) 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 | 7 +++++++ libstdc++-v3/include/std/variant | 3 ++- libstdc++-v3/testsuite/20_util/variant/compile.cc | 6 ++++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index e88fe2dcd4c..ec6e601c1ef 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,10 @@ +2017-02-15 Tim Shen + + 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 PR libstdc++/79348 diff --git a/libstdc++-v3/include/std/variant b/libstdc++-v3/include/std/variant index c5138e56803..866c4c40a61 100644 --- a/libstdc++-v3/include/std/variant +++ b/libstdc++-v3/include/std/variant @@ -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; diff --git a/libstdc++-v3/testsuite/20_util/variant/compile.cc b/libstdc++-v3/testsuite/20_util/variant/compile.cc index 65f4326c397..3bf9d5bfba3 100644 --- a/libstdc++-v3/testsuite/20_util/variant/compile.cc +++ b/libstdc++-v3/testsuite/20_util/variant/compile.cc @@ -291,6 +291,12 @@ void test_visit() }; static_assert(visit(Visitor(), variant(0)), ""); } + // PR libstdc++/79513 + { + std::variant v [[gnu::unused]] (5); + std::visit([](int&){}, v); + std::visit([](int&&){}, std::move(v)); + } } void test_constexpr() -- 2.30.2