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 731E43858D35 for ; Fri, 16 Jun 2023 13:52:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 731E43858D35 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=1686923560; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=h3ejag4PFaJy1TTq/CmRunXDRs80JSg3W5TWTaFXQFA=; b=SKCwOZaqt4Jw1NAPMdFRazC8TAOGF8f2bGAwQcm4vMu6U4DRMuw0HNW6r57Pa98wAb2Req Sf87rk8Je3SUrZG4PEusVGnN7DuC5ZaWQM4/l4Czub5jXEPvMseoQZOMybeOPm4TBnz1P7 NhD6I7jwCZTOUDah2HL+KpxE19PnoxY= Received: from mail-qk1-f199.google.com (mail-qk1-f199.google.com [209.85.222.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-111-4Qb6iD1KPQSt1XPXi4qjkg-1; Fri, 16 Jun 2023 09:52:38 -0400 X-MC-Unique: 4Qb6iD1KPQSt1XPXi4qjkg-1 Received: by mail-qk1-f199.google.com with SMTP id af79cd13be357-7623bd4b3bcso10819485a.1 for ; Fri, 16 Jun 2023 06:52:38 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686923558; x=1689515558; h=content-transfer-encoding:in-reply-to:from:references:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=h3ejag4PFaJy1TTq/CmRunXDRs80JSg3W5TWTaFXQFA=; b=MmODHdTzrEZ/rsGPZ9ixm9AEd+jbcGre/suV0u9GjcSARpDuN8Dwj1aH7t76AorKjj EtLSf9dauhgXtF5UE2LHVXjvkWBy3EYXTVzAt9ncQHV0KGAbSKqOubTe71ZTcSV3NH/B bfOdSUj/rbWWh0XNpS/RqwAcpkfiIjS9Lh29uyMfg8MFl6h7QGPZXBB9gM6/qV3dQE2E 3IKsUr79obN7PXkJLt4JM+ZWhe1qVOVCJ2yAcv0eeOyf+njnETxid/WxlPWixn7ZPBEI ma4Qo6yd77BQR5QjBu3IsKqnHJMCkqjwT1Hf5xtpB0P+AZlkz1l4X3A5pSexGVNeMdyJ iUDg== X-Gm-Message-State: AC+VfDyk0rw+sEqcG857EieZwbUZygO9qLfHnjwDec5bwIubF6e46SaL VloAgx1RSEep9XCiV9XHvD1N9R60AlENYcqfkMvL9fhxRr7uCoVKx96QWJM6Q+DbvshW7NU/IXz nZzLKw3G+9v4YgT8PUfrw3rwmaQ== X-Received: by 2002:a05:620a:2d8e:b0:760:7903:d433 with SMTP id tr14-20020a05620a2d8e00b007607903d433mr1670181qkn.70.1686923557864; Fri, 16 Jun 2023 06:52:37 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6XLR7GIIZt83HnhMfFXUgN4XxYM6DMrHFbucjTwPAUsPcZI4rJTNuMspJyIFlAUBu+gFTqKw== X-Received: by 2002:a05:620a:2d8e:b0:760:7903:d433 with SMTP id tr14-20020a05620a2d8e00b007607903d433mr1670168qkn.70.1686923557508; Fri, 16 Jun 2023 06:52:37 -0700 (PDT) Received: from [192.168.1.108] (130-44-146-16.s12558.c3-0.arl-cbr1.sbo-arl.ma.cable.rcncustomer.com. [130.44.146.16]) by smtp.gmail.com with ESMTPSA id u28-20020a05620a121c00b0074df2ac52f8sm2098950qkj.21.2023.06.16.06.52.36 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 16 Jun 2023 06:52:36 -0700 (PDT) Message-ID: <6b4579c6-909b-b489-7e02-8d4b607622fd@redhat.com> Date: Fri, 16 Jun 2023 09:52:35 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.12.0 Subject: Re: [PATCH] c++: diagnostic ICE b/c of empty TPARMS_PRIMARY_TEMPLATE [PR109655] To: Patrick Palka , gcc-patches@gcc.gnu.org References: <20230609151909.3628123-1-ppalka@redhat.com> From: Jason Merrill In-Reply-To: <20230609151909.3628123-1-ppalka@redhat.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-12.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,NICE_REPLY_A,RCVD_IN_DNSWL_NONE,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: On 6/9/23 11:19, Patrick Palka wrote: > When defining a previously declared class template, we neglect to set > TPARMS_PRIMARY_TEMPLATE for the in-scope template parameters, which the > class members go on to inherit, and so the members' DECL_TEMPLATE_PARMS > will have empty TPARMS_PRIMARY_TEMPLATE at those levels as well. This > causes us to crash when diagnosing a constraint mismatch for an > out-of-line declaration of a member of a constrained class template. > > This patch fixes this by walking the context to get at the corresponding > primary template instead. I spent a while trying to get us to set > TPARMS_PRIMARY_TEMPLATE for templated class definitions that are > redeclarations, but it proved to be hairy in particular for partial > specializations and nested templates. Maybe set it a bit earlier in push_template_decl, if you're going to figure out here what it should be anyway? > Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for > trunk/13? > > PR c++/109655 > > gcc/cp/ChangeLog: > > * pt.cc (push_template_decl): Handle TPARMS_PRIMARY_TEMPLATE > being empty when diagnosing a constraint mismatch for an > enclosing template scope. Don't bother checking constraints > if DECL_PARMS and SCOPE_PARMS are the same. > > gcc/testsuite/ChangeLog: > > * g++.dg/cpp2a/concepts-class6.C: New test. > * g++.dg/cpp2a/concepts-class6a.C: New test. > --- > gcc/cp/pt.cc | 19 +++++++-- > gcc/testsuite/g++.dg/cpp2a/concepts-class6.C | 30 ++++++++++++++ > gcc/testsuite/g++.dg/cpp2a/concepts-class6a.C | 40 +++++++++++++++++++ > 3 files changed, 86 insertions(+), 3 deletions(-) > create mode 100644 gcc/testsuite/g++.dg/cpp2a/concepts-class6.C > create mode 100644 gcc/testsuite/g++.dg/cpp2a/concepts-class6a.C > > diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc > index 17bf4d24151..f913b248345 100644 > --- a/gcc/cp/pt.cc > +++ b/gcc/cp/pt.cc > @@ -6155,12 +6155,25 @@ push_template_decl (tree decl, bool is_friend) > decl_parms = TREE_CHAIN (decl_parms); > scope_parms = TREE_CHAIN (scope_parms); > } > - while (decl_parms) > + while (decl_parms && decl_parms != scope_parms) > { > if (!template_requirements_equivalent_p (decl_parms, scope_parms)) > { > - error ("redeclaration of %qD with different constraints", > - TPARMS_PRIMARY_TEMPLATE (TREE_VALUE (decl_parms))); > + tree td = TPARMS_PRIMARY_TEMPLATE (TREE_VALUE (decl_parms)); > + if (!td) > + { > + /* FIXME: TPARMS_PRIMARY_TEMPLATE doesn't always get > + set for enclosing template scopes. Work around > + this by walking the context to obtain the relevant > + (primary) template whose constraints we mismatch. */ > + int level = TMPL_PARMS_DEPTH (decl_parms); > + td = TYPE_TI_TEMPLATE (ctx); > + while (!PRIMARY_TEMPLATE_P (td) > + || (TMPL_PARMS_DEPTH (DECL_TEMPLATE_PARMS (td)) > + != level)) > + td = TYPE_TI_TEMPLATE (DECL_CONTEXT (td)); > + } > + error ("redeclaration of %qD with different constraints", td); > break; > } > decl_parms = TREE_CHAIN (decl_parms); > diff --git a/gcc/testsuite/g++.dg/cpp2a/concepts-class6.C b/gcc/testsuite/g++.dg/cpp2a/concepts-class6.C > new file mode 100644 > index 00000000000..dcef6a2c9d4 > --- /dev/null > +++ b/gcc/testsuite/g++.dg/cpp2a/concepts-class6.C > @@ -0,0 +1,30 @@ > +// PR c++/109655 > +// { dg-do compile { target c++20 } } > + > +class C { > + template > + requires true > + friend class D; > + > + template > + requires true > + class E; > +}; > + > +template > +requires true > +class D { > + void f(); > +}; > + > +template > +void D::f() { } // { dg-error "class D' with different constraints" } > + > +template > +requires true > +class C::E { > + void f(); > +}; > + > +template > +void C::E::f() { } // { dg-error "class C::E' with different constraints" } > diff --git a/gcc/testsuite/g++.dg/cpp2a/concepts-class6a.C b/gcc/testsuite/g++.dg/cpp2a/concepts-class6a.C > new file mode 100644 > index 00000000000..751d13cdf6c > --- /dev/null > +++ b/gcc/testsuite/g++.dg/cpp2a/concepts-class6a.C > @@ -0,0 +1,40 @@ > +// PR c++/109655 > +// { dg-do compile { target c++20 } } > + > +template > +requires true > +class C { > + class D; > + > + template > + requires (!!true) > + class E; > +}; > + > +template > +requires true > +class C::D { > + void f(); > +}; > + > +template // missing "requires true" > +void C::D::f() { } // { dg-error "class C' with different constraints" } > + > +template > +requires true > +template > +requires (!!true) > +class C::E { > + void f(); > + void g(); > +}; > + > +template > +requires true > +template > +void C::E::f() { } // { dg-error "class C::E' with different constraints" } > + > +template > +template > +requires (!!true) > +void C::E::g() { } // { dg-error "class C' with different constraints" }