From 3203ed5f0182e7dbf1c74e6598e718641a3d4013 Mon Sep 17 00:00:00 2001 From: Tim Shen Date: Sun, 27 Nov 2016 00:32:04 +0000 Subject: [PATCH] re PR libstdc++/78441 ([variant] variant_alternative doesn't allow cv qualifiers) PR libstdc++/78441 * include/std/variant: Propagate cv qualifications to types returned by variant_alternative. * testsuite/20_util/variant/compile.cc: Tests. From-SVN: r242892 --- libstdc++-v3/ChangeLog | 7 +++++++ libstdc++-v3/include/std/variant | 12 ++++++++++++ libstdc++-v3/testsuite/20_util/variant/compile.cc | 9 +++++++++ 3 files changed, 28 insertions(+) diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index d663f70962f..4a26191fb8f 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,10 @@ +2016-11-26 Tim Shen + + PR libstdc++/78441 + * include/std/variant: Propagate cv qualifications to types returned + by variant_alternative. + * testsuite/20_util/variant/compile.cc: Tests. + 2016-11-23 Felix Morgner Jonathan Wakely diff --git a/libstdc++-v3/include/std/variant b/libstdc++-v3/include/std/variant index 7d935753728..34ad3fdefb0 100644 --- a/libstdc++-v3/include/std/variant +++ b/libstdc++-v3/include/std/variant @@ -85,6 +85,18 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION using variant_alternative_t = typename variant_alternative<_Np, _Variant>::type; + template + struct variant_alternative<_Np, const _Variant> + { using type = add_const_t>; }; + + template + struct variant_alternative<_Np, volatile _Variant> + { using type = add_volatile_t>; }; + + template + struct variant_alternative<_Np, const volatile _Variant> + { using type = add_cv_t>; }; + constexpr size_t variant_npos = -1; _GLIBCXX_END_NAMESPACE_VERSION diff --git a/libstdc++-v3/testsuite/20_util/variant/compile.cc b/libstdc++-v3/testsuite/20_util/variant/compile.cc index 2470bcc7f9e..e3330bef928 100644 --- a/libstdc++-v3/testsuite/20_util/variant/compile.cc +++ b/libstdc++-v3/testsuite/20_util/variant/compile.cc @@ -330,3 +330,12 @@ void test_adl() variant v8{allocator_arg, a, in_place_type, il, x}; variant v9{allocator_arg, a, in_place_type, 1}; } + +void test_variant_alternative() { + static_assert(is_same_v>, int>, ""); + static_assert(is_same_v>, string>, ""); + + static_assert(is_same_v>, const int>, ""); + static_assert(is_same_v>, volatile int>, ""); + static_assert(is_same_v>, const volatile int>, ""); +} -- 2.30.2