From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 A2B783858C2C for ; Mon, 17 Apr 2023 18:44:25 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A2B783858C2C Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1681757065; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=xmU3sMceu5PNwDv7sQacucb1cU/i4FVXSntSPd0GX1U=; b=HuSO6gvg7RpRD/dLorZ9mSicDsj29rmRTw2YZG9ajRKHmjNHG4dZma2RytnVZFSP+sOx2Q dl7TyCunxChnteAWqqd8XqEYF2o8f5LCHf6GXRM9LcCSeAI9v7mBPjr83vpWrhgA0MJRY7 g5IAqwHWaH7dlbyF+rkUb6RM5H25sEU= 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.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-303-qOSA8HOTOhKjuhk6ImOsdw-1; Mon, 17 Apr 2023 14:44:23 -0400 X-MC-Unique: qOSA8HOTOhKjuhk6ImOsdw-1 Received: by mail-qt1-f198.google.com with SMTP id b7-20020a05622a020700b003e38f7f800bso18418711qtx.9 for ; Mon, 17 Apr 2023 11:44:23 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681757062; x=1684349062; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=xmU3sMceu5PNwDv7sQacucb1cU/i4FVXSntSPd0GX1U=; b=gMSFpWtmXmLLJRKyhIIqnlQ5tyqwvJsMOKR+Uej8t5ArkKa9YM1Szy3Z2kfo+eoGnq vmSHlmL5mV226jsUhtPeOcBDhqagCxNysXQlBYnBngDPkqv6rTkqiZOJfYENxV+WAQAG QS7V89cMpV7qXTKeQlw4jM86E7tOz1ZEGexNthdPmLZt2trqqeP5rnlDi+yJzXp8QPi0 MXfhRUWmzoBV1FUahozU33SAXcmJ4wYe5K6ykQEyRsrkypks9Q5XeZQ+9CnhSOjxe7nB kHSr/+X4hv9fCiMjBn2k1Mp59Us7a6jlNcyj0HJ20ce5EK6WWXrEvp1yLFqi+NUZvvPW jcCg== X-Gm-Message-State: AAQBX9cGjMnElgkRaTcacMDA0RAMujZwv/M1Jyvep4ZADQi6hPVSeDrD ATT6emw6GoaUu7KXVQt/mBCuhnSfrwvTOPXqQu2TiIkF+Ofy7wPZEMSb11B314WImvjOa2/OPLf 3nsO/TvecZINJmVCllQy71KOIF+Q53V6IExCuJUQgIt25uBNn+yikRT58rXgW+Oczlg7dGZpsNX o= X-Received: by 2002:ad4:5748:0:b0:5ea:3abd:db61 with SMTP id q8-20020ad45748000000b005ea3abddb61mr21775640qvx.11.1681757062579; Mon, 17 Apr 2023 11:44:22 -0700 (PDT) X-Google-Smtp-Source: AKy350YKzVVS4mAHQiXs+78ndKp/XcOmE5HpSciOTreKJ37aYRTSFl0Bdw5KriAtfvO05QyQ5D93Dw== X-Received: by 2002:ad4:5748:0:b0:5ea:3abd:db61 with SMTP id q8-20020ad45748000000b005ea3abddb61mr21775601qvx.11.1681757062224; Mon, 17 Apr 2023 11:44:22 -0700 (PDT) Received: from localhost.localdomain (ool-457670bb.dyn.optonline.net. [69.118.112.187]) by smtp.gmail.com with ESMTPSA id g18-20020ac87752000000b003ecb3f292afsm2005648qtu.32.2023.04.17.11.44.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Apr 2023 11:44:21 -0700 (PDT) From: Patrick Palka To: gcc-patches@gcc.gnu.org Cc: jason@redhat.com, Patrick Palka Subject: [PATCH] c++: bound ttp level lowering [PR109531] Date: Mon, 17 Apr 2023 14:44:19 -0400 Message-ID: <20230417184419.4043285-1-ppalka@redhat.com> X-Mailer: git-send-email 2.40.0.335.g9857273be0 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true X-Spam-Status: No, score=-13.7 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,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 List-Id: Here when level lowering the bound ttp TT via the substitution T=C, we're neglecting to canonicalize (and therefore strip of simple typedefs) the resulting template arguments {A} before determining its new canonical type via hash table lookup. This leads to an a hash mismatch ICE for the two equivalent types TT and TT> since iterative_hash_template_arg misbehaves for a non-canonicalized type argument. We can fix this by canonicalizing or coercing the substituted arguments directly, but given that creation and ordinary substitution of bound ttps both go through lookup_template_class, which in turn performs coercion/canonicalization, it seems best to make this code path go through lookup_template_class as well. Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for trunk/13? PR c++/109531 gcc/cp/ChangeLog: * pt.cc (tsubst) : In the level-lowering case just use lookup_template_class to rebuild the bound ttp. gcc/testsuite/ChangeLog: * g++.dg/template/canon-type-20.C: New test. * g++.dg/template/ttp36.C: New test. --- gcc/cp/pt.cc | 39 ++++++++++--------- gcc/testsuite/g++.dg/template/canon-type-20.C | 18 +++++++++ gcc/testsuite/g++.dg/template/ttp36.C | 12 ++++++ 3 files changed, 50 insertions(+), 19 deletions(-) create mode 100644 gcc/testsuite/g++.dg/template/canon-type-20.C create mode 100644 gcc/testsuite/g++.dg/template/ttp36.C diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc index fcc8e0d1d57..e065ace5c55 100644 --- a/gcc/cp/pt.cc +++ b/gcc/cp/pt.cc @@ -16232,7 +16232,6 @@ tsubst (tree t, tree args, tsubst_flags_t complain, tree in_decl) { case TEMPLATE_TYPE_PARM: case TEMPLATE_TEMPLATE_PARM: - case BOUND_TEMPLATE_TEMPLATE_PARM: if (cp_type_quals (t)) { r = tsubst (TYPE_MAIN_VARIANT (t), args, complain, in_decl); @@ -16274,24 +16273,6 @@ tsubst (tree t, tree args, tsubst_flags_t complain, tree in_decl) only instantiated during satisfaction. */ PLACEHOLDER_TYPE_CONSTRAINTS_INFO (r) = ci; - if (code == BOUND_TEMPLATE_TEMPLATE_PARM) - { - tree tinfo = TYPE_TEMPLATE_INFO (t); - /* We might need to substitute into the types of non-type - template parameters. */ - tree tmpl = tsubst (TI_TEMPLATE (tinfo), args, - complain, in_decl); - if (tmpl == error_mark_node) - return error_mark_node; - tree argvec = tsubst (TI_ARGS (tinfo), args, - complain, in_decl); - if (argvec == error_mark_node) - return error_mark_node; - - TEMPLATE_TEMPLATE_PARM_TEMPLATE_INFO (r) - = build_template_info (tmpl, argvec); - } - if (TYPE_STRUCTURAL_EQUALITY_P (t)) SET_TYPE_STRUCTURAL_EQUALITY (r); else @@ -16299,6 +16280,26 @@ tsubst (tree t, tree args, tsubst_flags_t complain, tree in_decl) } break; + case BOUND_TEMPLATE_TEMPLATE_PARM: + { + tree tinfo = TYPE_TEMPLATE_INFO (t); + /* We might need to substitute into the types of non-type + template parameters. This also lowers the level of + the ttp appropriately. */ + tree tmpl = tsubst (TI_TEMPLATE (tinfo), args, + complain, in_decl); + if (tmpl == error_mark_node) + return error_mark_node; + tree argvec = tsubst (TI_ARGS (tinfo), args, + complain, in_decl); + if (argvec == error_mark_node) + return error_mark_node; + r = lookup_template_class (tmpl, argvec, in_decl, NULL_TREE, + /*entering_scope=*/false, complain); + r = cp_build_qualified_type (r, cp_type_quals (t), complain); + break; + } + case TEMPLATE_PARM_INDEX: /* OK, now substitute the type of the non-type parameter. We couldn't do it earlier because it might be an auto parameter, diff --git a/gcc/testsuite/g++.dg/template/canon-type-20.C b/gcc/testsuite/g++.dg/template/canon-type-20.C new file mode 100644 index 00000000000..e40261037e5 --- /dev/null +++ b/gcc/testsuite/g++.dg/template/canon-type-20.C @@ -0,0 +1,18 @@ +// PR c++/109531 +// { dg-do compile { target c++11 } } +// { dg-additional-options "--param=hash-table-verification-limit=1000" } + +template +using A = int; + +struct B { using type = int; }; +struct C { using type = A; }; + +template +struct D { + template class TT> + TT f (); +}; + +template struct D; +template struct D; diff --git a/gcc/testsuite/g++.dg/template/ttp36.C b/gcc/testsuite/g++.dg/template/ttp36.C new file mode 100644 index 00000000000..2df00855cf7 --- /dev/null +++ b/gcc/testsuite/g++.dg/template/ttp36.C @@ -0,0 +1,12 @@ +// Verify we propagate cv-quals when level-lowering a bound ttp. + +template +struct B { + template class TT> + void f(const TT *); + + template class TT> + void f(TT *); // { dg-bogus "cannot be overloaded" } +}; + +template struct B; -- 2.40.0.335.g9857273be0