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 C3202385770F for ; Thu, 18 May 2023 18:57:00 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C3202385770F 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=1684436220; 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=zooJKd538tKp9t4oQN0kKgoKt2LtL/JeITSRn37JKSw=; b=XHbEmK2WOKqIBhY03Ux5+LE10wRfyIxkC6eGq8hCz2+4IzrTDDhcFKOwC4ZGqQym8WESj1 lzYsfIrF38+9elmgU5jCjdQvA3WP8e8dZQEQP7TMYf1fQ9FCPaalQztDeRC6brp0FjhiOE 6jA4qD5d4GaWKvSWhoi4HhJ51wCg8LQ= 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-651-k36cT9h6Ml-bScqqXXkQ7g-1; Thu, 18 May 2023 14:56:59 -0400 X-MC-Unique: k36cT9h6Ml-bScqqXXkQ7g-1 Received: by mail-qv1-f69.google.com with SMTP id 6a1803df08f44-62388a2472eso13900126d6.1 for ; Thu, 18 May 2023 11:56:59 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684436218; x=1687028218; 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=zooJKd538tKp9t4oQN0kKgoKt2LtL/JeITSRn37JKSw=; b=V9aYL1qzJxZOePXSNVyCGc0KVZIG0RN4ogY2t+D8umHHs5WML/ePxCrYTeOv9ZnVQn +liab4NMh0zN3/H/yjMD9iuaWF9Fu5tabwo4DoDW2/QvAVpxfNqHnzvI/dzHMvpeAiaa rN6KIDcm+nk3x2gCuoWM35k3hirmnOliE7XxUUMrcCcu60sU5gniGmNhIbjtZW5iP2a4 lsJ0RStS6JDxHKqHNi74EtmOvCO+roNi4x/Mr03IUR0w6nqLr6u8/TIyanokamDbb+/k bClLy5z1QaHqYClVnhRUbT4K1MxPqgroeF9P6vHCvR+DI+0U88XDroYNQd02jrJ21Zcy ClPA== X-Gm-Message-State: AC+VfDy4bQCj1Sml4kWiYg1z4cShtaO5dWLOQNmOnfA1QX2CvR7E5lWY UhWGPPLbHCZczDsFg18UPn5Dlhd/b3SCCIPlRkskkfvSQD/4hjW0lXPIEeK2tc1ltRSGGgqlkyA MmP9g1M9J4LfLKdjYqcd9M7b+wg== X-Received: by 2002:a05:6214:4014:b0:623:686e:e426 with SMTP id kd20-20020a056214401400b00623686ee426mr129307qvb.4.1684436218567; Thu, 18 May 2023 11:56:58 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4g+aY64mbaJrW/LF0W9L21L7Jm9qfowGhXyOsIc54p4g7jqg+H43v5Alodiy4ptvOd+RhKQw== X-Received: by 2002:a05:6214:4014:b0:623:686e:e426 with SMTP id kd20-20020a056214401400b00623686ee426mr129266qvb.4.1684436217796; Thu, 18 May 2023 11:56:57 -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 ee14-20020a0562140a4e00b0061acac1e61bsm729194qvb.39.2023.05.18.11.56.57 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 18 May 2023 11:56:57 -0700 (PDT) Message-ID: Date: Thu, 18 May 2023 14:56:56 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.11.0 Subject: Re: [PATCH] c++: scoped variable template-id of reference type [PR97340] To: Patrick Palka , gcc-patches@gcc.gnu.org References: <20230518175927.4158045-1-ppalka@redhat.com> From: Jason Merrill In-Reply-To: <20230518175927.4158045-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=-14.1 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 5/18/23 13:59, Patrick Palka wrote: > lookup_and_finish_template_variable calls convert_from_reference, which > means for a variable template-id of reference type the function returns > an INDIRECT_REF instead of the bare VAR_DECL. But the downstream logic > of two callers, tsubst_qualified_id and finish_class_member_access_expr, > expect a DECL_P result and so we end up crashing when resolving the > template-id's in the first testcase. (Note that these two callers > eventually call convert_from_reference as appropriate, so this earlier > call seems at best redundant.) > > This patch fixes this by pulling out the convert_from_reference call > from lookup_and_finish_template_variable and into the callers that > actually need it, which turns out to be tsubst_copy_and_build (without > it we'd mishandle the second testcase). > > Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for > trunk? OK. > PR c++/97340 > > gcc/cp/ChangeLog: > > * pt.cc (lookup_and_finish_template_variable): Don't call > convert_from_reference. > (tsubst_copy_and_build) : Call > convert_from_reference on the result of > lookup_and_finish_template_variable. > > gcc/testsuite/ChangeLog: > > * g++.dg/cpp1y/var-templ80.C: New test. > * g++.dg/cpp1y/var-templ81.C: New test. > --- > gcc/cp/pt.cc | 3 ++- > gcc/testsuite/g++.dg/cpp1y/var-templ80.C | 22 ++++++++++++++++++++++ > gcc/testsuite/g++.dg/cpp1y/var-templ81.C | 14 ++++++++++++++ > 3 files changed, 38 insertions(+), 1 deletion(-) > create mode 100644 gcc/testsuite/g++.dg/cpp1y/var-templ80.C > create mode 100644 gcc/testsuite/g++.dg/cpp1y/var-templ81.C > > diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc > index 351fc18b600..9e5b29f3099 100644 > --- a/gcc/cp/pt.cc > +++ b/gcc/cp/pt.cc > @@ -10394,7 +10394,7 @@ lookup_and_finish_template_variable (tree templ, tree targs, > complain &= ~tf_partial; > var = finish_template_variable (var, complain); > mark_used (var); > - return convert_from_reference (var); > + return var; > } > > /* If the set of template parameters PARMS contains a template parameter > @@ -20462,6 +20462,7 @@ tsubst_copy_and_build (tree t, > { > tree r = lookup_and_finish_template_variable (templ, targs, > complain); > + r = convert_from_reference (r); > r = maybe_wrap_with_location (r, EXPR_LOCATION (t)); > RETURN (r); > } > diff --git a/gcc/testsuite/g++.dg/cpp1y/var-templ80.C b/gcc/testsuite/g++.dg/cpp1y/var-templ80.C > new file mode 100644 > index 00000000000..4439bee8292 > --- /dev/null > +++ b/gcc/testsuite/g++.dg/cpp1y/var-templ80.C > @@ -0,0 +1,22 @@ > +// PR c++/97340 > +// { dg-do compile { target c++14 } } > + > +template > +struct A { > + template > + static constexpr const int& var = 0; > +}; > + > +template > +struct B { > + static constexpr int x1 = A::template var; > + static constexpr int y1 = A{}.template var; > + > + static constexpr int x2 = A::template var; > + static constexpr int y2 = A{}.template var; > + > + static constexpr int x3 = A::template var; > + static constexpr int y3 = A{}.template var; > +}; > + > +template struct B; > diff --git a/gcc/testsuite/g++.dg/cpp1y/var-templ81.C b/gcc/testsuite/g++.dg/cpp1y/var-templ81.C > new file mode 100644 > index 00000000000..f9d2e6b1eed > --- /dev/null > +++ b/gcc/testsuite/g++.dg/cpp1y/var-templ81.C > @@ -0,0 +1,14 @@ > +// Verify we don't ICE on an invalid use of unary * for a variable > +// template-id of reference type. > +// { dg-do compile { target c++14 } } > + > +template > +static constexpr const int& var = 0; > + > +template > +struct B { > + static constexpr int x = *var; // { dg-error "argument of unary" } > + static constexpr const int& y = *var; // { dg-error "argument of unary" } > +}; > + > +template struct B;