From patchwork Thu Jan 27 16:58:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Palka X-Patchwork-Id: 50493 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 6C78B3850428 for ; Thu, 27 Jan 2022 16:59:19 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6C78B3850428 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1643302759; bh=WzwZ4dI8ZQ8wykoJh9XgjhVRJWOzuWWrZYZVFL3Uvrk=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=Bw57yaWAbCiKNOTi+i2QOoRtvomfTALElLyjgvZamjLRee8sBtryN4mqBcUY0FfmT L4aSJjE74wqpZwK8Bn5y483k2ukI4IdnyzZZ5sB5LOlxo/NqQ86OEslelZNXL0CxbR LzvXfpnPYkK6nYzeNOVfPNgRCTecbZg43Ov08aw4= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 65D513947429 for ; Thu, 27 Jan 2022 16:58:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 65D513947429 Received: from mail-qv1-f71.google.com (mail-qv1-f71.google.com [209.85.219.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-577-2B-CdLaSPP6lwV12Z6-g-g-1; Thu, 27 Jan 2022 11:58:18 -0500 X-MC-Unique: 2B-CdLaSPP6lwV12Z6-g-g-1 Received: by mail-qv1-f71.google.com with SMTP id iw14-20020a0562140f2e00b004204be8b6baso3744879qvb.3 for ; Thu, 27 Jan 2022 08:58:18 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=WzwZ4dI8ZQ8wykoJh9XgjhVRJWOzuWWrZYZVFL3Uvrk=; b=JgvVSy2UdDXqPChULPRC3VISGpegZ8cdR7oFVf5DOMR8Iz0BLObeZ0ysRHhrp8ZZOO CCgHU7cALOimLeSE2rtTLh9dNpwzxvINCjoAGDyd7rVvESjvTLiO8RPV5IE/kFv4LoNz 6pLwkL17dDRmkLNoyw5wNTpy0Ca7ZFkt8hkLfSmcsM3TwyR4SsKGESI9m9YIHBqGE2hZ AE2RC6d7rpNMOxrt8E+Yub7cC0BhVzbjoYqe3dWw9+G2fLwufMyA6RXjcvOZ0eBABgNj jVjKg7KHxu1+9EXilPzGVMSWe3WcNHf+I4shUOMrC4RTWV/viwhyLZHAwyXTONnrk4cB iZTA== X-Gm-Message-State: AOAM5306hN07gzdvXpwn9+5RJup9Y0gBgQQjsYrnAxIhaw+n55EE8zjO lN+5pm5vApYoc9Cqf8OCfxNiRkLlbOJ3IJhX7bWan9MC2DqYRIB445HnuwsDTt/Uk+B5sikf0FQ p1qwpc1vsDkqDYbs3Z+GB9u+P/bD3C3pIt8FmgClZWG97jc9UPKUp9DjZUHOngJ/P4uM= X-Received: by 2002:ae9:df41:: with SMTP id t62mr3366543qkf.214.1643302697570; Thu, 27 Jan 2022 08:58:17 -0800 (PST) X-Google-Smtp-Source: ABdhPJxM67n0S1rSIZ5cLOnVr6Bu0WlSVA609olZbQNAacyCaEL79F5s2iXI4A+T+tdQcCNwZVvenQ== X-Received: by 2002:ae9:df41:: with SMTP id t62mr3366533qkf.214.1643302697216; Thu, 27 Jan 2022 08:58:17 -0800 (PST) Received: from localhost.localdomain (ool-18e40894.dyn.optonline.net. [24.228.8.148]) by smtp.gmail.com with ESMTPSA id v73sm1626425qkb.51.2022.01.27.08.58.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Jan 2022 08:58:16 -0800 (PST) To: gcc-patches@gcc.gnu.org Subject: [PATCH] c++: var tmpl w/ dependent constrained auto type [PR103341] Date: Thu, 27 Jan 2022 11:58:14 -0500 Message-Id: <20220127165814.304303-1-ppalka@redhat.com> X-Mailer: git-send-email 2.35.0 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-14.4 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Patrick Palka via Gcc-patches From: Patrick Palka Reply-To: Patrick Palka Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" When deducing the type of a variable template specialization with a constrained auto type, we might need the template arguments for satisfaction in case the constraint is dependent. Bootstrapped and reegtested on x86_64-pc-linux-gnu, does this look OK for trunk and perhaps 11? PR c++/103341 gcc/cp/ChangeLog: * decl.cc (cp_finish_decl): Pass the template arguments of a variable template specialization to do_auto_deduction when the auto is constrained. gcc/testsuite/ChangeLog: * g++.dg/cpp2a/concepts-var-templ2.C: New test. --- gcc/cp/decl.cc | 7 ++++++- gcc/testsuite/g++.dg/cpp2a/concepts-var-templ2.C | 13 +++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/cpp2a/concepts-var-templ2.C diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc index 10e6956117e..b698fa9b95a 100644 --- a/gcc/cp/decl.cc +++ b/gcc/cp/decl.cc @@ -7958,9 +7958,14 @@ cp_finish_decl (tree decl, tree init, bool init_const_expr_p, enum auto_deduction_context adc = adc_variable_type; if (VAR_P (decl) && DECL_DECOMPOSITION_P (decl)) adc = adc_decomp_type; + tree outer_targs = NULL_TREE; + if (is_constrained_auto (auto_node) + && variable_template_specialization_p (decl)) + /* The outer template arguments might be needed for satisfaction. */ + outer_targs = DECL_TI_ARGS (decl); type = TREE_TYPE (decl) = do_auto_deduction (type, d_init, auto_node, tf_warning_or_error, adc, - NULL_TREE, flags); + outer_targs, flags); if (type == error_mark_node) return; if (TREE_CODE (type) == FUNCTION_TYPE) diff --git a/gcc/testsuite/g++.dg/cpp2a/concepts-var-templ2.C b/gcc/testsuite/g++.dg/cpp2a/concepts-var-templ2.C new file mode 100644 index 00000000000..56cead5e8c3 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp2a/concepts-var-templ2.C @@ -0,0 +1,13 @@ +// PR c++/103341 +// { dg-do compile { target c++20 } } + +template concept same_as = __is_same(T, U); +template same_as auto v1a{1}; +template same_as auto v1b{1}; +template same_as auto v2a{T()}; // { dg-error "constraints" } +template same_as auto v2b{T()}; // { dg-error "constraints" } + +template int v1a; +template int v1b; +template int v2a; // { dg-message "required from here" } +template int v2b; // { dg-message "required from here" }