From patchwork Tue Apr 5 16:30:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 1613508 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=IEmiHqfj; 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 (ip-8-43-85-97.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 (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KXtRb3DZ3z9sFk for ; Wed, 6 Apr 2022 02:30:35 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 8F2E7385741D for ; Tue, 5 Apr 2022 16:30:33 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8F2E7385741D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1649176233; bh=gnHL7T8orJofKXMtaN3GcxVq6GtGD/ykjqZ+yKlXyGU=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=IEmiHqfjVrLLUwAIphAvyeUP1qkRizeCPh+qJVsXgu9hMiOWoDqgJwuhHyXuEUV+0 lFMneVKAijQdhx2NJT9SNWqRArrXT6OaemQfXVk/R+pnjB1A2RMNJ2SVNFbO8BNelA WWcLVQDEiSkgYmvFQW/KtGh7mDvcu9KlzYJFF4/w= 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 392E03858D1E for ; Tue, 5 Apr 2022 16:30:11 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 392E03858D1E Received: from mail-qt1-f198.google.com (mail-qt1-f198.google.com [209.85.160.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-395-gE7v7cXeNMioNU9wBdau-g-1; Tue, 05 Apr 2022 12:30:08 -0400 X-MC-Unique: gE7v7cXeNMioNU9wBdau-g-1 Received: by mail-qt1-f198.google.com with SMTP id e5-20020ac85985000000b002e217abd72fso9439217qte.9 for ; Tue, 05 Apr 2022 09:30:08 -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=gnHL7T8orJofKXMtaN3GcxVq6GtGD/ykjqZ+yKlXyGU=; b=CHT8dcJkuAygrsfwYscoEzRWcgiyA21nFgaAivxj7UlR3E+QfOHFxGXygI9NV7lyTZ jNZqU+nfzJiKFi0QM1eP/hAeI2lkg+5T3g2aZs42a35A7lg6aFD3h560O5MXC7qWRRrh zrGYhhfLk4JxGWB/5hBldHWgY9rSPf/Zdv/uGb3hAXvLeSbBYgsgXVHs/ZlqsWiWYme+ v6xb09Y622SSL3rRil1VmcDP0wpSft6fYTpiGVVpqDU4/uXHiS6esY2wJYNk3UIo4d7t 5lr4l54o4A3X1sDqEiwrGTWbiKMrSQjEB3FK0MdP2XmlAzeGQT68KTMR4m7HtjxYfjGd X5DQ== X-Gm-Message-State: AOAM533Ohd+pU4Pg3cFcX2A3D/tYWYbFa74A/t4hFO6qF3kEhAFbIQZV /Us/IsTi3NwljIpsbTnwVa1Ovre5doRS0RtWAyCyhG7j+HShLjYBvN7rmqwmmXSioMu5cLATKQM sG1xYaYRpmTVzAhQTwtIhIBbCK4AnfejbI7dHUJPx/iWytlo5ulRDhy/ChRmN5QCI0A== X-Received: by 2002:a05:622a:58f:b0:2e1:eb89:60b5 with SMTP id c15-20020a05622a058f00b002e1eb8960b5mr3811613qtb.166.1649176207644; Tue, 05 Apr 2022 09:30:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzYk3mEL5VaG3MWt+NexIS4LUABhsMQ1CmOTNF6yDdJQQwzrVsTDbbD8Y5Lctay/x5YVM2TMA== X-Received: by 2002:a05:622a:58f:b0:2e1:eb89:60b5 with SMTP id c15-20020a05622a058f00b002e1eb8960b5mr3811570qtb.166.1649176207115; Tue, 05 Apr 2022 09:30:07 -0700 (PDT) Received: from barrymore.cygnus.csb (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 m19-20020a05620a13b300b0067b4cc3041fsm7994728qki.115.2022.04.05.09.30.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Apr 2022 09:30:06 -0700 (PDT) To: gcc-patches@gcc.gnu.org Subject: [pushed] c++: alias template equivalence and CTAD [PR103852] Date: Tue, 5 Apr 2022 12:30:04 -0400 Message-Id: <20220405163004.2099642-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.0 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_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE 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: 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" I had been thinking about DR1286 "equivalence" as meaning generally interchangeable, but looking back at the proposed resolution in the context of this PR, I see that it's just about use as a template argument. So let's give a pedwarn if we look through a renaming alias. Tested x86_64-pc-linux-gnu, applying to trunk. PR c++/103852 DR 1286 gcc/cp/ChangeLog: * pt.cc (do_class_deduction): Pedwarn for renaming alias in C++17. gcc/testsuite/ChangeLog: * g++.dg/cpp1z/class-deduction-alias1.C: Expect warning. --- gcc/cp/pt.cc | 26 +++++++++++++++---- .../g++.dg/cpp1z/class-deduction-alias1.C | 3 ++- 2 files changed, 23 insertions(+), 6 deletions(-) base-commit: 1de6612d994ada8edaab18bbc6afd8e9a57413aa diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc index 1f0231f70e6..eeebc4c1ef3 100644 --- a/gcc/cp/pt.cc +++ b/gcc/cp/pt.cc @@ -29909,8 +29909,6 @@ do_class_deduction (tree ptype, tree tmpl, tree init, && CLASS_PLACEHOLDER_TEMPLATE (TREE_TYPE (init)) == tmpl) return cp_build_qualified_type (TREE_TYPE (init), cp_type_quals (ptype)); - /* Look through alias templates that just rename another template. */ - tmpl = get_underlying_template (tmpl); if (!ctad_template_p (tmpl)) { if (complain & tf_error) @@ -29920,15 +29918,33 @@ do_class_deduction (tree ptype, tree tmpl, tree init, else if (cxx_dialect < cxx20 && DECL_ALIAS_TEMPLATE_P (tmpl)) { if (complain & tf_error) - error ("alias template deduction only available " - "with %<-std=c++20%> or %<-std=gnu++20%>"); - return error_mark_node; + { + /* Be permissive with equivalent alias templates. */ + tree u = get_underlying_template (tmpl); + diagnostic_t dk = (u == tmpl) ? DK_ERROR : DK_PEDWARN; + bool complained + = emit_diagnostic (dk, input_location, 0, + "alias template deduction only available " + "with %<-std=c++20%> or %<-std=gnu++20%>"); + if (u == tmpl) + return error_mark_node; + else if (complained) + { + inform (input_location, "use %qD directly instead", u); + tmpl = u; + } + } + else + return error_mark_node; } /* Wait until the initializer is non-dependent. */ if (type_dependent_expression_p (init)) return ptype; + /* Don't bother with the alias rules for an equivalent template. */ + tmpl = get_underlying_template (tmpl); + tree type = TREE_TYPE (tmpl); bool try_list_ctor = false; diff --git a/gcc/testsuite/g++.dg/cpp1z/class-deduction-alias1.C b/gcc/testsuite/g++.dg/cpp1z/class-deduction-alias1.C index 1ec90b58e3a..ffa5f2bad94 100644 --- a/gcc/testsuite/g++.dg/cpp1z/class-deduction-alias1.C +++ b/gcc/testsuite/g++.dg/cpp1z/class-deduction-alias1.C @@ -1,5 +1,6 @@ // PR c++/103852 // { dg-do compile { target c++17 } } +// { dg-options "" } template struct b{}; template > @@ -10,7 +11,7 @@ struct s s c(100); template > using ss = s; // equivalent under proposed resolution of DR 1286 -ss tt(1); // OK +ss tt(1); // { dg-warning "alias template deduction" "" { target c++17_only } } template using ss2 = s; // different default arg makes it non-equivalent