From patchwork Tue Nov 22 06:46:58 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tim Shen X-Patchwork-Id: 83337 Delivered-To: patch@linaro.org Received: by 10.140.97.165 with SMTP id m34csp1949141qge; Mon, 21 Nov 2016 22:47:23 -0800 (PST) X-Received: by 10.98.63.1 with SMTP id m1mr23207433pfa.31.1479797243826; Mon, 21 Nov 2016 22:47:23 -0800 (PST) Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id 14si26854984pfu.95.2016.11.21.22.47.23 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 21 Nov 2016 22:47:23 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-return-442191-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-442191-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-442191-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=NVpt2jS71d12tdgvrKYsFKlfdCA9/O/HKU919qG57T2pil iRZTjbfTeqlV7XnphA0wnEkuhvCNXfd60+rAgokFm33QahwAX7ooYpx5Qgp/r4wN 5lvIlV85MtAnWEzRQ7lMrC81JAxtBWoEtlOVjV90RH0a60T0P2VEUqiiTavBk= 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=YncgWwUgXYVImWNIjbUTd/zkSz8=; b=KOsw5AmCzXIWJmSwfnso ayTzpFy3Ni51AUOKi58ZpXLmEymmvMrZX3LEspB1WKwvs289r3N5KrVpoJQl/kOV uoDrBsewe7R+d+Oq8Z2TFs/iSRNtiFQ/bmVWIatjVM2pMtQdiZs0nCIORzLQidhr Z8ebk8k4MEGm0anB7vUvXTo= Received: (qmail 100275 invoked by alias); 22 Nov 2016 06:47:12 -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 100245 invoked by uid 89); 22 Nov 2016 06:47:10 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-4.9 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_NONE, RP_MATCHES_RCVD, SPF_PASS autolearn=ham version=3.3.2 spammy=85, 6, sk:_GLIBCX, sk:_glibcx, H*F:D*google.com X-HELO: mail-ua0-f175.google.com Received: from mail-ua0-f175.google.com (HELO mail-ua0-f175.google.com) (209.85.217.175) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 22 Nov 2016 06:47:00 +0000 Received: by mail-ua0-f175.google.com with SMTP id b35so7002902uaa.3 for ; Mon, 21 Nov 2016 22:47:00 -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=XWNDtXMJvZdtUeciD11wxyGo5vRXFKt9c2JiJQEsqSs=; b=H8TVnfWpwEmo73jnC+3624b3si1Hg/YFeEn8X3KD+PgIWSPb9z7kgt00FmA2LCfpNk D1dFxO+EX0mLptoZuJYYAOeEiXnkF4OumlqWp0Km9/4rKIYk3UDN6NGxwBeZoZd8JbXX 2NELzB2V4TqTiJCRYKvAch8gA/dkNbb5NHQRxbds+f49S9crDYFqu8wPf9Se1LtpgzBX X3dq7CEHZE8+viSYhslB9PPCwKYiUP+id5T5bZtA7tz0TstqwgAB7wsViqEo878lO1mx z4oDaltFC7Jy2BIUL0hD362726+pzFKV+PG1vz5ZU+jYK3aWFXwCNlexBx3lIMR3kdPD sp4g== X-Gm-Message-State: AKaTC01mSwLwD32N/6SK5mQfUyd/ZsWH6NJDxgGYv0QKGcrH4SMvE5PuCV0tfbhRCK7+QgmPh9Ous8j+BZyyTuue X-Received: by 10.159.38.111 with SMTP id 102mr9438111uag.155.1479797218788; Mon, 21 Nov 2016 22:46:58 -0800 (PST) MIME-Version: 1.0 Received: by 10.103.31.69 with HTTP; Mon, 21 Nov 2016 22:46:58 -0800 (PST) From: Tim Shen Date: Mon, 21 Nov 2016 22:46:58 -0800 Message-ID: Subject: [PATCH] Propagate cv qualifications in variant_alternative To: "libstdc++" , gcc-patches Tested on x86_64-linux-gnu. Thanks! -- Regards, Tim Shen commit 69c72d9bb802fd5e4f2704f0fe8a041f8b26d8bd Author: Tim Shen Date: Mon Nov 21 21:29:13 2016 -0800 2016-11-22 Tim Shen PR libstdc++/78441 * include/std/variant: Propagate cv qualifications to types returned by variant_alternative. * testsuite/20_util/variant/compile.cc: Tests. diff --git a/libstdc++-v3/include/std/variant b/libstdc++-v3/include/std/variant index 7d93575..34ad3fd 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 2470bcc..e3330be 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>, ""); +}