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 EBB8B381FE78 for ; Fri, 16 Sep 2022 12:08:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org EBB8B381FE78 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=1663330086; 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=7K4PKY+Xp6CWD0Syibw67RQHFc8OifwqZia5KO6Ge8E=; b=b0Pye9VACOMHrg2+mHpzGPpC9CRuC5w6qxhuga8jtQSyCj+5RTSgQfsvGf+PDgBJtyTrmp 5phxC197JT6pebbkvcGdtA/LqSBD+RnbI7PKCwXumLY1IuQv1Y3Emoi6lHp+OV3RTBJi49 Hl4lRlThgaQMu7YtaUT72zQJUMoGuAc= Received: from mail-ej1-f72.google.com (mail-ej1-f72.google.com [209.85.218.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-217-lWl5hVseNv2QOvaVQONTmw-1; Fri, 16 Sep 2022 08:08:05 -0400 X-MC-Unique: lWl5hVseNv2QOvaVQONTmw-1 Received: by mail-ej1-f72.google.com with SMTP id xh12-20020a170906da8c00b007413144e87fso8941910ejb.14 for ; Fri, 16 Sep 2022 05:08:04 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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; bh=7K4PKY+Xp6CWD0Syibw67RQHFc8OifwqZia5KO6Ge8E=; b=dDjEjTjWePJyFOkjKmnb3+pfwwyWPbQ5ZB2W+I4koAURJVCd7LV86HHoL/LMMeTdRr wx+jc798yK6bR87eYS3mQZLZv2UlBV3mVYUthmN2zSCPqzsAStkMrAUhDXlDJXXaISTt pB3rmb3g+PWUh0TwXBQP35MgqaLkCPXx0TwxnZXAwmcS9SArY2Ky4ViLNyCQZ24nCxp3 j2+2q2a5DAwTppbIjdVtYHju3+qh3l9z1YaTt1TXFvbBrpGfF+1zfUeMNUXub1PilYtG cxdPWQlyE4GhSWAadPnxG+BQhB/nLPCY8yGdAguU03bHN6k3pboXVl6f5edxl9wGtS8+ Hpmg== X-Gm-Message-State: ACrzQf0NfyK76TwHtqSlA/c8PUvkPohp+WBtUeId6wmM029mMIu6i9zf 8WHjmqzjqC3BzJW71IXJ0lRgLNNy8hSkFAL3XeKv8fPDUQs4juuJJmv+ztY7WRguQKEXs4N3o0w od5iE40wu/5jhocrvBw== X-Received: by 2002:a05:6402:2c6:b0:44e:7d0a:c231 with SMTP id b6-20020a05640202c600b0044e7d0ac231mr3626589edx.283.1663330083402; Fri, 16 Sep 2022 05:08:03 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6YJBEtWKNJvI411KczXqUl6Grjy3VZXtPRUArwceMp1xvKO6o1QtEJlNEyMM9ujrrH7yhfUw== X-Received: by 2002:a05:6402:2c6:b0:44e:7d0a:c231 with SMTP id b6-20020a05640202c600b0044e7d0ac231mr3626571edx.283.1663330083014; Fri, 16 Sep 2022 05:08:03 -0700 (PDT) Received: from [10.9.7.96] (vpn-konference.ms.mff.cuni.cz. [195.113.20.101]) by smtp.gmail.com with ESMTPSA id s25-20020aa7cb19000000b004531b137e4bsm2535009edt.67.2022.09.16.05.08.02 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 16 Sep 2022 05:08:02 -0700 (PDT) Message-ID: <549844d1-be60-592b-5e2b-1e4071f6a7f8@redhat.com> Date: Fri, 16 Sep 2022 14:08:01 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.13.0 Subject: Re: [PATCH] c++: constraint matching, TEMPLATE_ID_EXPR, current inst To: Patrick Palka , gcc-patches@gcc.gnu.org References: <20220915155822.4021344-1-ppalka@redhat.com> From: Jason Merrill In-Reply-To: <20220915155822.4021344-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=-13.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_LOW,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 List-Id: On 9/15/22 11:58, Patrick Palka wrote: > Here we're crashing during constraint matching for the instantiated > hidden friends due to two issues with dependent substitution into a > TEMPLATE_ID_EXPR naming a template from the current instantiation > (as performed from maybe_substitute_reqs_for for C<3> with T=T): > > * tsubst_copy substitutes into such a TEMPLATE_DECL by looking it > up from the substituted class scope. But for this to not fail when > the args are dependent, we need to pass entering_scope=true for the > class scope substitution so that we obtain the primary template type > A (which has TYPE_BINFO) instead of the implicit instantiation > A (which doesn't). > * lookup_and_finish_template_variable shouldn't instantiate a > TEMPLATE_ID_EXPR that names a TEMPLATE_DECL which has more than > one level of (unsubstituted) parameters (such as A::C). > > Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for > trunk? > > gcc/cp/ChangeLog: > > * pt.cc (lookup_and_finish_template_variable): Don't > instantiate if the template's scope is dependent. > (tsubst_copy) : Pass entering_scope=true > when substituting the class scope. > > gcc/testsuite/ChangeLog: > > * g++.dg/cpp2a/concepts-friend10.C: New test. > --- > gcc/cp/pt.cc | 14 +++++++------ > .../g++.dg/cpp2a/concepts-friend10.C | 21 +++++++++++++++++++ > 2 files changed, 29 insertions(+), 6 deletions(-) > create mode 100644 gcc/testsuite/g++.dg/cpp2a/concepts-friend10.C > > diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc > index db4e808adec..bfcbe0b8670 100644 > --- a/gcc/cp/pt.cc > +++ b/gcc/cp/pt.cc > @@ -10475,14 +10475,15 @@ tree > lookup_and_finish_template_variable (tree templ, tree targs, > tsubst_flags_t complain) > { > - templ = lookup_template_variable (templ, targs); > - if (!any_dependent_template_arguments_p (targs)) > + tree var = lookup_template_variable (templ, targs); > + if (TMPL_PARMS_DEPTH (DECL_TEMPLATE_PARMS (templ)) == 1 > + && !any_dependent_template_arguments_p (targs)) I notice that finish_id_expression_1 uses the equivalent of type_dependent_expression_p (var). Does that work here? > { > - templ = finish_template_variable (templ, complain); > - mark_used (templ); > + var = finish_template_variable (var, complain); > + mark_used (var); > } > > - return convert_from_reference (templ); > + return convert_from_reference (var); > } > > /* If the set of template parameters PARMS contains a template parameter > @@ -17282,7 +17283,8 @@ tsubst_copy (tree t, tree args, tsubst_flags_t complain, tree in_decl) > TEMPLATE_DECL with `D' as its DECL_CONTEXT. Now we > have to substitute this with one having context `D'. */ > > - tree context = tsubst (DECL_CONTEXT (t), args, complain, in_decl); > + tree context = tsubst_aggr_type (DECL_CONTEXT (t), args, complain, > + in_decl, /*entering_scope=*/true); > return lookup_field (context, DECL_NAME(t), 0, false); > } > else This hunk is OK. > diff --git a/gcc/testsuite/g++.dg/cpp2a/concepts-friend10.C b/gcc/testsuite/g++.dg/cpp2a/concepts-friend10.C > new file mode 100644 > index 00000000000..4b21a379f59 > --- /dev/null > +++ b/gcc/testsuite/g++.dg/cpp2a/concepts-friend10.C > @@ -0,0 +1,21 @@ > +// { dg-do compile { target c++20 } } > +// Verify we don't crash during constraint matching containing > +// a TEMPLATE_ID_EXPR referring to a template from the current > +// instantiation. > + > +template > +struct A { > + template static constexpr bool C = sizeof(T) > N; > + friend constexpr void f(A) requires C<3> { } > + friend constexpr void f(A) requires C<3> || true { } > +}; > + > +template > +struct A { > + template static constexpr bool C = sizeof(T) > N; > + friend constexpr void g(A) requires C<3> { } > + friend constexpr void g(A) requires C<3> || true { } > +}; > + > +template struct A; > +template struct A;