From patchwork Wed Mar 29 02:23:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 1762529 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: legolas.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=BaF3uY2B; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4PmVjb2TB3z1yYb for ; Wed, 29 Mar 2023 13:24:01 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 910C13858417 for ; Wed, 29 Mar 2023 02:23:57 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 910C13858417 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1680056637; bh=MfofIDCmb9ZVwQwroji6bUXvw0h4btGemI0u+Tx4pNk=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=BaF3uY2BH6vfrXSBUm4fi4DI3j6+5cVV65faJE+pkA9NhCMVySXxEWcwIPwz3027R GU+JgQt67lSVFCKMthOwzwFj/gqaZJnkiu3GyqRixXiuenvvNJ1TB1jmtstz0qgiAY 3w0LFTBiPElgM37MsARr5xAVISxV94EWoxSgTjnk= 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 395D03858D39 for ; Wed, 29 Mar 2023 02:23:34 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 395D03858D39 Received: from mail-qv1-f69.google.com (mail-qv1-f69.google.com [209.85.219.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-219-GXn7n5kRPvCsItTfLoBV8g-1; Tue, 28 Mar 2023 22:23:32 -0400 X-MC-Unique: GXn7n5kRPvCsItTfLoBV8g-1 Received: by mail-qv1-f69.google.com with SMTP id l15-20020a0cd6cf000000b005df451a51ddso1912461qvi.9 for ; Tue, 28 Mar 2023 19:23:32 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680056611; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=MfofIDCmb9ZVwQwroji6bUXvw0h4btGemI0u+Tx4pNk=; b=pkzYGKD4M7WtFjTdDYNn2FlGT9IB3wNTVg1kEI3eh0lhA147J3KFo5BIuMQvuju4H/ nwHC1yIVhXw2uWhtenUshzcSpMAq/mpBKXjWtSRa+QTVM0H7pmrDhWR6qo9FZPSwKleY ZMFEAYseIdkphBfkCOQ/q4m7CgPqThIEhBp6jpJYvqqS4R+AY7YkiUr8ZV0oisnNQyfe DgczfTnGYMeldx8SF7gpnIdlWnYQ20DQlMY5MafUYd6tOofQxs2Wm8x8+xT66ZW2Pujb KQ3QX4kg82dbSOWz6ifq5mKmOeVDgT7EpltAj5BfJcNyM1REJvOtZb1Kdlq6cUmJ1KHM GFZA== X-Gm-Message-State: AAQBX9cIhNKCCETxzdmS3ptUdqxmTbLTNHUNA5ut8A3W5lrCYoWLmUPE KlEyaR33gvQmc0HGypwwghn0Uc7efg4I95k1Cpdkip7hl09CyJa6XLZ2ywxlw3quA5YQTgAdEIM h8BA6EAKiEQE1t1PEqASuxrB4IX04cI2rfvYVAv4cxchrVp0rsEkSlP6E8TpYdaJYQg45Phk0FA == X-Received: by 2002:a05:6214:2269:b0:5d1:d9f3:dd83 with SMTP id gs9-20020a056214226900b005d1d9f3dd83mr1539162qvb.7.1680056611262; Tue, 28 Mar 2023 19:23:31 -0700 (PDT) X-Google-Smtp-Source: AKy350YBs/xQl61qRWdVBiYq4R/2e74xsH2WF4j+SweVD4laM3D0BLMk8XgJDhM7n/9w9v+55/UyXQ== X-Received: by 2002:a05:6214:2269:b0:5d1:d9f3:dd83 with SMTP id gs9-20020a056214226900b005d1d9f3dd83mr1539129qvb.7.1680056610803; Tue, 28 Mar 2023 19:23:30 -0700 (PDT) Received: from jason.cygnus.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 px20-20020a056214051400b005dd8b934570sm4249993qvb.8.2023.03.28.19.23.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Mar 2023 19:23:30 -0700 (PDT) To: gcc-patches@gcc.gnu.org Subject: [pushed] c++: alias ctad refinements [PR109321] Date: Tue, 28 Mar 2023 22:23:27 -0400 Message-Id: <20230329022327.99330-1-jason@redhat.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.6 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_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP 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" Tested x86_64-pc-linux-gnu, applying to trunk. -- 8< -- The two hunks fix missing handling demonstrated by the two testcases: first, if we omit one alias template parm but include another, we need to rewrite the deduced template args to reflect the new position of the included parm. Second, if we can't deduce any template args for a parameter pack, it is deduced to an empty pack. PR c++/109321 PR c++/109320 gcc/cp/ChangeLog: * pt.cc (alias_ctad_tweaks): Rewrite deduced args. (type_targs_deducible_from): Handle null pack deduction. gcc/testsuite/ChangeLog: * g++.dg/cpp2a/class-deduction-alias16.C: New test. * g++.dg/cpp2a/class-deduction-alias17.C: New test. --- gcc/cp/pt.cc | 62 ++++++++++++++----- .../g++.dg/cpp2a/class-deduction-alias16.C | 7 +++ .../g++.dg/cpp2a/class-deduction-alias17.C | 9 +++ 3 files changed, 64 insertions(+), 14 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp2a/class-deduction-alias16.C create mode 100644 gcc/testsuite/g++.dg/cpp2a/class-deduction-alias17.C base-commit: b3c5933ee726004e4e47291d422dfe7ac3345062 diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc index 3bb98ebeac1..e514a277872 100644 --- a/gcc/cp/pt.cc +++ b/gcc/cp/pt.cc @@ -30123,8 +30123,8 @@ alias_ctad_tweaks (tree tmpl, tree uguides) for (unsigned i = 0; i < len; ++i) TREE_VEC_ELT (targs, i) = NULL_TREE; - /* The number of parms for f' is the number of parms for A plus - non-deduced parms of f. */ + /* The number of parms for f' is the number of parms of A used in + the deduced arguments plus non-deduced parms of f. */ unsigned ndlen = 0; unsigned j; for (unsigned i = 0; i < len; ++i) @@ -30142,22 +30142,34 @@ alias_ctad_tweaks (tree tmpl, tree uguides) TREE_VALUE (current_template_parms) = gtparms; j = 0; - /* First copy over the parms of A. */ + unsigned level = 1; + + /* First copy over the used parms of A. */ + tree atargs = make_tree_vec (natparms); for (unsigned i = 0; i < natparms; ++i) { tree elt = TREE_VEC_ELT (atparms, i); if (ftpi.found (elt)) - TREE_VEC_ELT (gtparms, j++) = elt; + { + unsigned index = j++; + tree nelt = rewrite_tparm_list (elt, index, level, + atargs, i, complain); + TREE_VEC_ELT (gtparms, index) = nelt; + } } gcc_checking_assert (j == nusedatparms); + /* Adjust the deduced template args for f to refer to the A parms + with their new indexes. */ + if (nusedatparms && nusedatparms != natparms) + targs = tsubst_template_args (targs, atargs, complain, in_decl); + /* Now rewrite the non-deduced parms of f. */ for (unsigned i = 0; ndlen && i < len; ++i) if (TREE_VEC_ELT (targs, i) == NULL_TREE) { --ndlen; unsigned index = j++; - unsigned level = 1; tree oldlist = TREE_VEC_ELT (ftparms, i); tree list = rewrite_tparm_list (oldlist, index, level, targs, i, complain); @@ -30261,15 +30273,37 @@ type_targs_deducible_from (tree tmpl, tree type) /* We don't fail on an undeduced targ the second time through (like get_partial_spec_bindings) because we're going to try defaults. */ - if (!tried_array_deduction) - for (int i = 0; i < len; ++i) - if (! TREE_VEC_ELT (targs, i)) - { - try_array_deduction (tparms, targs, TREE_TYPE (tmpl)); - tried_array_deduction = true; - if (TREE_VEC_ELT (targs, i)) - goto again; - } + for (int i = 0; i < len; ++i) + if (! TREE_VEC_ELT (targs, i)) + { + tree tparm = TREE_VEC_ELT (tparms, i); + tparm = TREE_VALUE (tparm); + + if (!tried_array_deduction + && TREE_CODE (tparm) == TYPE_DECL) + { + try_array_deduction (tparms, targs, TREE_TYPE (tmpl)); + tried_array_deduction = true; + if (TREE_VEC_ELT (targs, i)) + goto again; + } + /* If the type parameter is a parameter pack, then it will be deduced + to an empty parameter pack. This is another case that doesn't model + well as partial specialization. */ + if (template_parameter_pack_p (tparm)) + { + tree arg; + if (TREE_CODE (tparm) == TEMPLATE_PARM_INDEX) + { + arg = make_node (NONTYPE_ARGUMENT_PACK); + TREE_CONSTANT (arg) = 1; + } + else + arg = cxx_make_type (TYPE_ARGUMENT_PACK); + ARGUMENT_PACK_ARGS (arg) = make_tree_vec (0); + TREE_VEC_ELT (targs, i) = arg; + } + } /* Maybe add in default template args. This seems like a flaw in the specification in terms of partial specialization, since it says the diff --git a/gcc/testsuite/g++.dg/cpp2a/class-deduction-alias16.C b/gcc/testsuite/g++.dg/cpp2a/class-deduction-alias16.C new file mode 100644 index 00000000000..53d305b5c71 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp2a/class-deduction-alias16.C @@ -0,0 +1,7 @@ +// PR c++/109321 +// { dg-do compile { target c++20 } } + +struct A; +template struct B; +template using D = B; +void f () { D() = 0; } // { dg-error "deduction failed|no match" } diff --git a/gcc/testsuite/g++.dg/cpp2a/class-deduction-alias17.C b/gcc/testsuite/g++.dg/cpp2a/class-deduction-alias17.C new file mode 100644 index 00000000000..b8346895b5b --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp2a/class-deduction-alias17.C @@ -0,0 +1,9 @@ +// PR c++/109320 +// { dg-do compile { target c++20 } } + +template +struct S {}; +template +using u = S; +struct X {}; +auto a = u {};