From patchwork Wed May 25 18:49:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 1635604 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=VIxIXlyl; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4L7gBn3zKJz9s2R for ; Thu, 26 May 2022 04:51:13 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A5A0C3856DD2 for ; Wed, 25 May 2022 18:51:11 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A5A0C3856DD2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1653504671; bh=DObNi2Q8mdWuVAMFbo7hd0oIZT3sgKwCMrf2Tm0YcUw=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=VIxIXlylvZSTKLFoVqJ7c1Db9YcjmNiXVBIByxSCmbg/E897X6quLEqXqmiYvKf5A 8C+5MUh7ZWoOWKo4g+UCU1GfwL9E276i94oBbT0edQ95tqzEDS+Q6NQj0g8yfmz/Z6 X+LojfW2ryQA/TXlIp7NVffiF55CWshWhmQSr5lU= 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 D338B385041A for ; Wed, 25 May 2022 18:50:00 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org D338B385041A Received: from mail-qv1-f70.google.com (mail-qv1-f70.google.com [209.85.219.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-249-QkJcVBtZMAqxWO-EVdUMOA-1; Wed, 25 May 2022 14:49:59 -0400 X-MC-Unique: QkJcVBtZMAqxWO-EVdUMOA-1 Received: by mail-qv1-f70.google.com with SMTP id j11-20020a0cc34b000000b0046265b1d3e0so1411854qvi.23 for ; Wed, 25 May 2022 11:49:59 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=DObNi2Q8mdWuVAMFbo7hd0oIZT3sgKwCMrf2Tm0YcUw=; b=NI9bcOw+lvFtHZh+AGgjgghLHsTQ4WB5Wpg6UkD0AcjzTPa29Mfu8/AxDJM4pBDm2Z eAoE1WDDueFrltVlQ98a2a7+D1UXTJflqrSTe8yyOWmFlyhizql2DCjESqWvEKz/G6LV 4CDWT88Ss4I0Gj743UrrN+rGGzCFxVrPn4u9wvuzZAZSrKS9qnNJ7YLwse4Yqg6N/VGS Zkhz5nXxIcpBkW/nZBRUj2Xlx7prv8dMQVIl7k1mhLXxG26yJityKwpd5gsvvs5gJWLv vhejtUyi8DB4hmGv9ff1TkzF3pgc12GCE9HS/3ODrW+0N8aOFbhlUlDqlDJe75TmbaTO K1ZA== X-Gm-Message-State: AOAM533cDlh1ASih9ke1pC2oGwblRGdGq1r9q1/9hoQ3Yb0rmg6E3AcE 7B+W6dORsY3qRVTzd2byDqTV4hdgQweCkPTI9reMAnw++gftkOLynNvE1WPxKBB0d4FKpqZREjL NEeeMlkmXxmFUAhNAz233Q3paoz5FTM+fh5QhmuUMFgC/nfD4JkSWgUIEdkn3g1MZzQ== X-Received: by 2002:a05:6214:20a7:b0:45b:f666:d3db with SMTP id 7-20020a05621420a700b0045bf666d3dbmr26639292qvd.0.1653504598262; Wed, 25 May 2022 11:49:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzwmK6Y3YJIa5LTxHUmt9gRUCMXBb7yeQJc/bpaIymRKnY0A5ozi8/qMNKZa4Pq8NCwEzYIFg== X-Received: by 2002:a05:6214:20a7:b0:45b:f666:d3db with SMTP id 7-20020a05621420a700b0045bf666d3dbmr26639271qvd.0.1653504597835; Wed, 25 May 2022 11:49:57 -0700 (PDT) Received: from barrymore.redhat.com (130-44-159-43.s15913.c3-0.arl-cbr1.sbo-arl.ma.cable.rcncustomer.com. [130.44.159.43]) by smtp.gmail.com with ESMTPSA id o17-20020a05620a2a1100b0069fca79fa3asm1949174qkp.62.2022.05.25.11.49.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 May 2022 11:49:56 -0700 (PDT) To: gcc-patches@gcc.gnu.org Subject: [pushed] c++: CTAD with alias and nested template [PR105655] Date: Wed, 25 May 2022 14:49:54 -0400 Message-Id: <20220525184954.1133162-1-jason@redhat.com> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-13.5 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, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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: Jason Merrill via Gcc-patches From: Jason Merrill Reply-To: Jason Merrill Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" Here, alias_ctad_tweaks expect tsubst_decl of a FUNCTION_DECL to return a FUNCTION_DECL. A reasonable expectation, but in this case we were replacing the template args of the class-scope deduction guide with equivalent args, so looking in the hash table we found the partial instantiation stored when instantiating A, which is a TEMPLATE_DECL. It's fine for that to be what is stored, but tsubst_function_decl should never return it. Tested x86_64-pc-linux-gnu, applying to trunk. PR c++/105655 gcc/cp/ChangeLog: * pt.cc (build_template_decl): Add assert. (tsubst_function_decl): Don't return a template. gcc/testsuite/ChangeLog: * g++.dg/cpp2a/class-deduction-alias13.C: New test. --- gcc/cp/pt.cc | 6 ++++- .../g++.dg/cpp2a/class-deduction-alias13.C | 24 +++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/cpp2a/class-deduction-alias13.C base-commit: 850a9ce8bcca59c7efabcdeeca14c5bd905e8363 diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc index 76913cb1409..021af019840 100644 --- a/gcc/cp/pt.cc +++ b/gcc/cp/pt.cc @@ -5021,6 +5021,8 @@ maybe_update_decl_type (tree orig_type, tree scope) static tree build_template_decl (tree decl, tree parms, bool member_template_p) { + gcc_checking_assert (TREE_CODE (decl) != TEMPLATE_DECL); + tree tmpl = build_lang_decl (TEMPLATE_DECL, DECL_NAME (decl), NULL_TREE); SET_DECL_LANGUAGE (tmpl, DECL_LANGUAGE (decl)); DECL_TEMPLATE_PARMS (tmpl) = parms; @@ -14074,7 +14076,9 @@ tsubst_function_decl (tree t, tree args, tsubst_flags_t complain, { hash = hash_tmpl_and_args (gen_tmpl, argvec); if (tree spec = retrieve_specialization (gen_tmpl, argvec, hash)) - return spec; + /* The spec for these args might be a partial instantiation of the + template, but here what we want is the FUNCTION_DECL. */ + return STRIP_TEMPLATE (spec); } } else diff --git a/gcc/testsuite/g++.dg/cpp2a/class-deduction-alias13.C b/gcc/testsuite/g++.dg/cpp2a/class-deduction-alias13.C new file mode 100644 index 00000000000..0a90a83081b --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp2a/class-deduction-alias13.C @@ -0,0 +1,24 @@ +// PR c++/105655 +// { dg-do compile { target c++20 } } + +template +struct A +{ + template + struct B + { + B(const L & left, const R & right) + {} + }; + + template + B(const L &, const R &) -> B; +}; + +template +using C = A::B; + +int main() +{ + C x{0, 0}; +}