From 7b277e8b464b28c76a751fbb811c419d79a3f715 Mon Sep 17 00:00:00 2001 From: Tim Shen Date: Tue, 15 Nov 2016 17:26:59 +0000 Subject: [PATCH] variant: Remove variant... * include/std/variant: Remove variant, variant, variant<> support to rebase on the post-Issaquah design. * testsuite/20_util/variant/compile.cc: Likewise. From-SVN: r242437 --- libstdc++-v3/ChangeLog | 10 +- libstdc++-v3/include/std/variant | 77 ++------- .../testsuite/20_util/variant/compile.cc | 149 +----------------- 3 files changed, 28 insertions(+), 208 deletions(-) diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 54bf54d0023..cc72f15c4b8 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,9 @@ +2016-11-15 Tim Shen + + * include/std/variant: Remove variant, variant, variant<> support + to rebase on the post-Issaquah design. + * testsuite/20_util/variant/compile.cc: Likewise. + 2016-11-15 Matthias Klose * configure: Regenerate. @@ -341,9 +347,9 @@ 2016-11-09 Tim Shen - * libstdc++-v3/include/bits/regex.h (regex_iterator::regex_iterator()): + * include/bits/regex.h (regex_iterator::regex_iterator()): Define end() as _M_pregex == nullptr. - * libstdc++-v3/include/bits/regex.tcc (regex_iterator::operator==(), + * include/bits/regex.tcc (regex_iterator::operator==(), regex_iterator::operator++()): Fix operator==() and operator++() to look at null-ness of _M_pregex on both sides. * testsuite/28_regex/regression.cc: New testcase. diff --git a/libstdc++-v3/include/std/variant b/libstdc++-v3/include/std/variant index 6f3f67c5780..7d935753728 100644 --- a/libstdc++-v3/include/std/variant +++ b/libstdc++-v3/include/std/variant @@ -137,41 +137,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION struct __reserved_type_map_impl { using type = add_cv_t<__reserved_type_map<_From, _To>>; }; - // Stores a reference alternative as a... well, reference. - template - struct _Reference_storage - { - static_assert(is_reference_v<_Reference>, - "BUG: _Reference should be a reference"); - - _Reference_storage(_Reference __ref) noexcept : _M_storage(__ref) { } - - operator _Reference() noexcept - { return static_cast<_Reference>(_M_storage); } - - _Reference _M_storage; - }; - - // Stores a void alternative, because it is not a regular type. - template - struct _Void_storage { }; - - // Map from the alternative type to a non-qualified storage type. - template - struct __storage_type - { using type = _Alternative; }; - - template - struct __storage_type<_Alternative, - enable_if_t>> - { using type = _Reference_storage<_Alternative>; }; - + // This abstraction might be useful for future features, + // e.g. boost::recursive_wrapper. template - struct __storage_type<_Alternative, enable_if_t>> - { using type = _Void_storage<_Alternative>; }; - - template - using __storage = typename __storage_type<_Type>::type; + using __storage = _Alternative; template> struct _Uninitialized; @@ -202,37 +171,15 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION _M_storage; }; - // Reverse mapping of __storage_type. - template - struct __alternative_type - { - static_assert(!is_reference_v<_Storage_type>, - "BUG: _Storage_type should not be reference"); - using type = _Storage_type; - }; - - template - struct __alternative_type<_Reference_storage<_Reference>> - { using type = _Reference; }; - - template - struct __alternative_type<_Void_storage<_Void>> - { using type = _Void; }; - // Given a qualified storage type, return the desired reference. - // The qualified storage type is supposed to carry the variant object's - // qualifications and reference information, and the designated alternative's - // storage type. - // Returns the qualification-collapsed alternative references. - // - // For example, __get_alternative<_Reference_storage&> returns int&. + // For example, variant&& stores the int as __storage, and + // _Qualified_storage will be __storage&&. template decltype(auto) __get_alternative(void* __ptr) { using _Storage = decay_t<_Qualified_storage>; - using _Alternative = typename __alternative_type<_Storage>::type; - return __reserved_type_map<_Qualified_storage, _Alternative>( + return __reserved_type_map<_Qualified_storage, _Storage>( *static_cast<_Storage*>(__ptr)); } @@ -970,6 +917,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION variant<_Types...>> { private: + static_assert(sizeof...(_Types) > 0, + "variant must have at least one alternative"); + static_assert(!(std::is_reference_v<_Types> || ...), + "variant must have no reference alternative"); + static_assert(!(std::is_void_v<_Types> || ...), + "variant must have no void alternative"); + using _Base = __detail::__variant::_Variant_base<_Types...>; using _Default_ctor_enabler = _Enable_default_constructor< @@ -1265,11 +1219,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION __get_storage(_Vp&& __v); }; - // To honor algebraic data type, variant<> should be a bottom type, which - // is 0 (as opposed to a void type, which is 1). Use incomplete type to model - // bottom type. - template<> class variant<>; - template variant_alternative_t<_Np, variant<_Types...>>& get(variant<_Types...>& __v) diff --git a/libstdc++-v3/testsuite/20_util/variant/compile.cc b/libstdc++-v3/testsuite/20_util/variant/compile.cc index 08de71e7cce..2470bcc7f9e 100644 --- a/libstdc++-v3/testsuite/20_util/variant/compile.cc +++ b/libstdc++-v3/testsuite/20_util/variant/compile.cc @@ -55,7 +55,6 @@ void default_ctor() { static_assert(is_default_constructible_v>, ""); static_assert(is_default_constructible_v>, ""); - static_assert(!is_default_constructible_v>, ""); static_assert(!is_default_constructible_v>, ""); static_assert(is_default_constructible_v>, ""); @@ -123,14 +122,6 @@ void uses_alloc_ctors() std::allocator alloc; variant a(allocator_arg, alloc); static_assert(!is_constructible_v, allocator_arg_t, std::allocator>, ""); - { - variant b(allocator_arg, alloc, a); - static_assert(!is_constructible_v, allocator_arg_t, std::allocator, const variant&>, ""); - } - { - variant b(allocator_arg, alloc, std::move(a)); - static_assert(!is_constructible_v, allocator_arg_t, std::allocator, variant&&>, ""); - } { variant b(allocator_arg, alloc, "a"); static_assert(!is_constructible_v, allocator_arg_t, std::allocator, const char*>, ""); @@ -169,12 +160,6 @@ void copy_assign() variant a; static_assert(!noexcept(a = a), ""); } - - { - float f1 = 1.0f, f2 = 2.0f; - std::variant v1(f1); - v1 = f2; - } } void move_assign() @@ -203,103 +188,13 @@ void arbitrary_assign() void test_get() { - { - static_assert(is_same(variant())), int&&>::value, ""); - static_assert(is_same(variant())), string&&>::value, ""); - static_assert(is_same(variant())), string&>::value, ""); - static_assert(is_same(variant())), string&&>::value, ""); - static_assert(is_same(variant())), const string&&>::value, ""); - static_assert(is_same(variant())), const string&>::value, ""); - static_assert(is_same(variant())), const string&&>::value, ""); - - static_assert(is_same(variant())), int&&>::value, ""); - static_assert(is_same(variant())), string&&>::value, ""); - static_assert(is_same(variant())), string&>::value, ""); - static_assert(is_same(variant())), string&&>::value, ""); - static_assert(is_same(variant())), const string&&>::value, ""); - static_assert(is_same(variant())), const string&>::value, ""); - static_assert(is_same(variant())), const string&&>::value, ""); - } - { - variant a; - variant b; - variant c; - variant d; - variant e; - variant f; - - static_assert(is_same(a)), int&>::value, ""); - static_assert(is_same(a)), string&>::value, ""); - static_assert(is_same(b)), string&>::value, ""); - static_assert(is_same(c)), string&>::value, ""); - static_assert(is_same(e)), const string&>::value, ""); - static_assert(is_same(e)), const string&>::value, ""); - static_assert(is_same(f)), const string&>::value, ""); - - static_assert(is_same(a)), int&>::value, ""); - static_assert(is_same(a)), string&>::value, ""); - static_assert(is_same(b)), string&>::value, ""); - static_assert(is_same(c)), string&>::value, ""); - static_assert(is_same(e)), const string&>::value, ""); - static_assert(is_same(e)), const string&>::value, ""); - static_assert(is_same(f)), const string&>::value, ""); - - static_assert(is_same(&a)), int*>::value, ""); - static_assert(is_same(&a)), string*>::value, ""); - static_assert(is_same(&b)), string*>::value, ""); - static_assert(is_same(&c)), string*>::value, ""); - static_assert(is_same(&e)), const string*>::value, ""); - static_assert(is_same(&e)), const string*>::value, ""); - static_assert(is_same(&f)), const string*>::value, ""); - - static_assert(is_same(&a)), int*>::value, ""); - static_assert(is_same(&a)), string*>::value, ""); - static_assert(is_same(&b)), string*>::value, ""); - static_assert(is_same(&c)), string*>::value, ""); - static_assert(is_same(&e)), const string*>::value, ""); - static_assert(is_same(&e)), const string*>::value, ""); - static_assert(is_same(&f)), const string*>::value, ""); - } - { - const variant a; - const variant b; - const variant c; - const variant d; - const variant e; - const variant f; - - static_assert(is_same(a)), const int&>::value, ""); - static_assert(is_same(a)), const string&>::value, ""); - static_assert(is_same(b)), string&>::value, ""); - static_assert(is_same(c)), string&>::value, ""); - static_assert(is_same(d)), const string&>::value, ""); - static_assert(is_same(e)), const string&>::value, ""); - static_assert(is_same(f)), const string&>::value, ""); - - static_assert(is_same(a)), const int&>::value, ""); - static_assert(is_same(a)), const string&>::value, ""); - static_assert(is_same(b)), string&>::value, ""); - static_assert(is_same(c)), string&>::value, ""); - static_assert(is_same(d)), const string&>::value, ""); - static_assert(is_same(e)), const string&>::value, ""); - static_assert(is_same(f)), const string&>::value, ""); - - static_assert(is_same(&a)), const int*>::value, ""); - static_assert(is_same(&a)), const string*>::value, ""); - static_assert(is_same(&b)), string*>::value, ""); - static_assert(is_same(&c)), string*>::value, ""); - static_assert(is_same(&d)), const string*>::value, ""); - static_assert(is_same(&e)), const string*>::value, ""); - static_assert(is_same(&f)), const string*>::value, ""); - - static_assert(is_same(&a)), const int*>::value, ""); - static_assert(is_same(&a)), const string*>::value, ""); - static_assert(is_same(&b)), string*>::value, ""); - static_assert(is_same(&c)), string*>::value, ""); - static_assert(is_same(&d)), const string*>::value, ""); - static_assert(is_same(&e)), const string*>::value, ""); - static_assert(is_same(&f)), const string*>::value, ""); - } + static_assert(is_same(variant())), int&&>::value, ""); + static_assert(is_same(variant())), string&&>::value, ""); + static_assert(is_same(variant())), const string&&>::value, ""); + + static_assert(is_same(variant())), int&&>::value, ""); + static_assert(is_same(variant())), string&&>::value, ""); + static_assert(is_same(variant())), const string&&>::value, ""); } void test_relational() @@ -344,16 +239,6 @@ void test_visit() void operator()(monostate) const {} void operator()(const int&) const {} }; - variant a; - const variant b; - Visitor v; - const CVisitor u; - static_assert(is_same::value, ""); - static_assert(is_same::value, ""); - static_assert(is_same::value, ""); - static_assert(is_same::value, ""); - static_assert(is_same::value, ""); - static_assert(is_same::value, ""); } { struct Visitor @@ -397,19 +282,6 @@ void test_constexpr() } } -void test_void() -{ - static_assert(is_same(variant()))>::value, ""); - static_assert(!is_default_constructible_v>, ""); - static_assert(!is_copy_constructible_v>, ""); - static_assert(!is_move_constructible_v>, ""); - static_assert(!is_copy_assignable_v>, ""); - static_assert(!is_move_assignable_v>, ""); - variant v; - v = 3; - v = "asdf"; -} - void test_pr77641() { struct X { @@ -457,11 +329,4 @@ void test_adl() variant v7{allocator_arg, a, in_place_index<0>, il, x}; variant v8{allocator_arg, a, in_place_type, il, x}; variant v9{allocator_arg, a, in_place_type, 1}; - - std::variant vr0(x); - vr0 = x; - variant vr1{in_place_index<0>, x}; - variant vr2{in_place_type, x}; - variant vr3{allocator_arg, a, in_place_index<0>, x}; - variant vr4{allocator_arg, a, in_place_type, x}; } -- 2.30.2