From patchwork Sat Nov 12 20:11:30 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tim Shen X-Patchwork-Id: 81930 Delivered-To: patch@linaro.org Received: by 10.140.97.165 with SMTP id m34csp367772qge; Sat, 12 Nov 2016 12:12:18 -0800 (PST) X-Received: by 10.98.223.203 with SMTP id d72mr20231655pfl.2.1478981538595; Sat, 12 Nov 2016 12:12:18 -0800 (PST) Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id m26si16182213pge.303.2016.11.12.12.12.18 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 12 Nov 2016 12:12:18 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-return-441234-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org; spf=pass (google.com: domain of gcc-patches-return-441234-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-441234-patch=linaro.org@gcc.gnu.org; dmarc=fail (p=REJECT dis=NONE) header.from=google.com DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :mime-version:from:date:message-id:subject:to:content-type; q= dns; s=default; b=XZ6OXL7/1oI+we2mJG55xOdQyKUwTMIwjkhKooqjGfMJzb AAP+IpFoO+E1zirWrHpt+JNefX0BLIAH2qX3B3/QKlRNg7ZrarsXot2Hc22XR395 dyVQfkOFsL1nEnyjfsI0I8eSNpU9w7MNTkiladXBGgYK5QQL7yCtylYnr4vXc= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :mime-version:from:date:message-id:subject:to:content-type; s= default; bh=pZWMGZaTsiMWpw9FdmvjGMU773M=; b=LwKaBhTriA17SQ7RFlsq oEwL77SIrYnbY7mFslA41nHZRFN3FH/xyQWfv/0r32HGOL8zXNSG+F3SPSEPR1aQ ThRWTe/dxfQCotZuOo40xrMS1utSktuz5Ke6xC8nDN0fC++AgkhiOs/M7X4xgtfB hrBsk82YvqkSfY6OHIcnBRo= Received: (qmail 101111 invoked by alias); 12 Nov 2016 20:11:44 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 101084 invoked by uid 89); 12 Nov 2016 20:11:43 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-4.0 required=5.0 tests=AWL, BAYES_00, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_NONE, RP_MATCHES_RCVD, SPF_PASS autolearn=ham version=3.3.2 spammy=designated, sk:is_defa, qualified, 160, 6 X-HELO: mail-vk0-f41.google.com Received: from mail-vk0-f41.google.com (HELO mail-vk0-f41.google.com) (209.85.213.41) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sat, 12 Nov 2016 20:11:32 +0000 Received: by mail-vk0-f41.google.com with SMTP id 137so38050376vkl.0 for ; Sat, 12 Nov 2016 12:11:32 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=IBKkjmYMJ9jKTrH9qM3ugtKAfiKdN64EotQjsajtF70=; b=QmMjaWD86fWakLM9VpPithkPYVRzGxIaPPuDXykY5y7WtDRt2ahnmLEU25v2hYebII KuTDazgbej3Rj02queSRTN3b/mEKjrCbgSQK8oRWmZl+xyVzcT7fIkqZDEGQ4szLImcd HUzqWSG5KlvP1XLMde53ryFL/iBx+m5u2qQYfkPjKffFLRBuWHRBGXDc0q8r7gFmKD5E ou1mKSZPTd3HdmytnvvK6qtiFbgu75Ff/E6k+VTEgO54bCrpkahd4IxntN2RzvTgBXV4 FCzr8N2BjPm3ARcbBY2nPDfDtB/+jd9vWJqNTh0cttRQjYMsReIW9kqD/TA4Fbxl9E3v VEHg== X-Gm-Message-State: ABUngvdOKD6OclAEGA4w4u+h3u5YKb+97A5dEt+Rqlj35IOEyya5W4H+9AL6te1dbQK1CgCpTu/JgqIuLUQw/Tuf X-Received: by 10.31.83.133 with SMTP id h127mr6032523vkb.147.1478981490822; Sat, 12 Nov 2016 12:11:30 -0800 (PST) MIME-Version: 1.0 Received: by 10.103.31.69 with HTTP; Sat, 12 Nov 2016 12:11:30 -0800 (PST) From: Tim Shen Date: Sat, 12 Nov 2016 12:11:30 -0800 Message-ID: Subject: [Patch] Remove variant, variant and variant<> To: "libstdc++" , gcc-patches At Issaquah we decided to remove the supports above. Bootstrapped and tested on x86_64-linux-gnu. Thanks! -- Regards, Tim Shen Index: libstdc++-v3/include/std/variant =================================================================== --- libstdc++-v3/include/std/variant (revision 242337) +++ libstdc++-v3/include/std/variant (working copy) @@ -136,42 +136,11 @@ 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; }; - + // This abstraction might be useful for future features, + // e.g. boost::recursive_wrapper. template - struct __storage_type<_Alternative, - enable_if_t>> - { using type = _Reference_storage<_Alternative>; }; + using __storage = _Alternative; - template - struct __storage_type<_Alternative, enable_if_t>> - { using type = _Void_storage<_Alternative>; }; - - template - using __storage = typename __storage_type<_Type>::type; - template> struct _Uninitialized; @@ -201,37 +170,15 @@ _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)); } @@ -969,6 +916,13 @@ 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< @@ -1264,11 +1218,6 @@ __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) Index: libstdc++-v3/testsuite/20_util/variant/compile.cc =================================================================== --- libstdc++-v3/testsuite/20_util/variant/compile.cc (revision 242337) +++ libstdc++-v3/testsuite/20_util/variant/compile.cc (working copy) @@ -55,7 +55,6 @@ { 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>, ""); @@ -124,14 +123,6 @@ 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 @@ 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 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())), 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, ""); } void test_relational() @@ -344,16 +239,6 @@ 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_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 @@ variant v7{allocator_arg, a, in_place<0>, il, x}; variant v8{allocator_arg, a, in_place, il, x}; variant v9{allocator_arg, a, in_place, 1}; - - std::variant vr0(x); - vr0 = x; - variant vr1{in_place<0>, x}; - variant vr2{in_place, x}; - variant vr3{allocator_arg, a, in_place<0>, x}; - variant vr4{allocator_arg, a, in_place, x}; }