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.133.124]) by sourceware.org (Postfix) with ESMTPS id 14CE23858C2C for ; Thu, 10 Mar 2022 04:14:50 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 14CE23858C2C Received: from mail-qt1-f199.google.com (mail-qt1-f199.google.com [209.85.160.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-612-KtNLzA4kPHSoKkAs1bpefg-1; Wed, 09 Mar 2022 23:14:45 -0500 X-MC-Unique: KtNLzA4kPHSoKkAs1bpefg-1 Received: by mail-qt1-f199.google.com with SMTP id x10-20020ac8700a000000b002c3ef8fc44cso3134726qtm.8 for ; Wed, 09 Mar 2022 20:14:44 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:cc:references:from:in-reply-to :content-transfer-encoding; bh=OW+e3rkYgo4DRLPmHF5jXCXkI9umxjtz8fTSrxOrBSQ=; b=vGJAhmK42/5qDsbILiIQu7XCJ0G2Y9h+nmK+8WaRsst+Geut3H/2MaWzshJ0ighAPC gQMLdGs8VR2d3YmBEVzXzsF/A7bt7uAO9grtvqjVC7naCVEnoMCa2JKD57zXjHtE/QXX 54IOiBdDSxclVtouByaBElmVAyrbaetIuEAEKxkVDFVg9WwTKwjzMEtAFjp7mMbwRaI4 4uuot0xI5MH7RXaTnt3oEtzpr3yAooOekYyx/N4whuw87W0Wp0zTIA4YiQY47lbgoNwm tIfmdntIi3+VG9Wb4CQKvLfdFhzspNLgYJUzT4OzyEUsirM1lMq9aA+F9eRJKBSivQ0F 5Qsw== X-Gm-Message-State: AOAM533QCIW3qPkZgyeOjp66n95FHLDwDzIR4R1XeQw54MmD203TrEMQ ZyUnAGH+pa0uR41Qs7CEHxa77frMqWRGTcruaD273Y0FPceLG8RmQ/qPRLMSOsPUVf/EJCKWKhy lErFf+8AyuJeGGcTjww== X-Received: by 2002:a05:622a:178d:b0:2e1:a593:2d63 with SMTP id s13-20020a05622a178d00b002e1a5932d63mr2411683qtk.563.1646885684458; Wed, 09 Mar 2022 20:14:44 -0800 (PST) X-Google-Smtp-Source: ABdhPJwcJgZxC4VISQxpRW3/MP5PMQc/tygFN0JegY+ktqUh9l+xZ5JJPrth6q19s8SGiMRZLqEn+Q== X-Received: by 2002:a05:622a:178d:b0:2e1:a593:2d63 with SMTP id s13-20020a05622a178d00b002e1a5932d63mr2411676qtk.563.1646885684127; Wed, 09 Mar 2022 20:14:44 -0800 (PST) Received: from [192.168.1.149] (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 7-20020ac85747000000b002de73a851ffsm2520416qtx.89.2022.03.09.20.14.42 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 09 Mar 2022 20:14:43 -0800 (PST) Message-ID: <4e2978b2-93e6-e32c-b5c1-9cb77b726ac9@redhat.com> Date: Wed, 9 Mar 2022 23:14:42 -0500 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.6.1 Subject: Re: [PATCH v2] c++: ->template and implicit typedef [PR104608] To: Marek Polacek Cc: GCC Patches References: <20220222214617.1949703-1-polacek@redhat.com> From: Jason Merrill In-Reply-To: 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, RCVD_IN_MSPIKE_H5, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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-List-Received-Date: Thu, 10 Mar 2022 04:14:51 -0000 On 3/1/22 17:12, Marek Polacek wrote: > On Mon, Feb 28, 2022 at 12:31:37PM -0400, Jason Merrill wrote: >> On 2/22/22 17:46, Marek Polacek wrote: >>> Here we have a forward declaration of Parameter for which we create >>> an implicit typedef, which is a TYPE_DECL. Then, when looking it up >>> at template definition time, cp_parser_template_id gets (since r12-6754) >>> this TYPE_DECL which it can't handle. >> >> Hmm, getting that global TYPE_DECL from lookup seems like a bug; isn't the >> lookup earlier in cp_parser_template_name in object scope? > > Yes, it is (in Function), but I think we do the pre-DR1835 lookup. For > > this->template Parameter(); > > we don't find Parameter in the object expression's type (Function), so we do > unqualified lookup in the enclosing context and find the global Parameter > TYPE_DECL. This is implemented in cp_parser_lookup_name: > > decl = lookup_member (object_type, name, ...); > if (!decl) > decl = lookup_name (name, ...); > > [basic.lookup.qual.general] now says that we only perform unqualified lookup > if the object type isn't dependent. But I don't think we can fix this by > implementing DR1835 because that would only help in C++23(?). > > My v1 patch is wrong in any case; I've come up with template-keyword4.C > where we find a TYPE_DECL which is not an implicit typedef. > > Since cp_parser_template_id is only able to handle these TYPE_DECLs: > > 18353 else if (TREE_CODE (templ) == TYPE_DECL > 18354 && TREE_CODE (TREE_TYPE (templ)) == TYPENAME_TYPE) > > this v2 patch fixes the problem by repeating lookup of TYPE_DECLs whose > TREE_TYPE is *not* TYPENAME_TYPE. That fixes my testcases and doesn't > regress any. > > Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk? OK. > -- >8 -- > Here we have a forward declaration of Parameter for which we create > an implicit typedef, which is a TYPE_DECL. Then, when looking it up > at template definition time, cp_parser_template_id gets (since r12-6754) > this TYPE_DECL which it can't handle. > > This patch defers lookup for TYPE_DECLs that cp_parser_template_id can't > handle, a la r12-6879. > > PR c++/104608 > > gcc/cp/ChangeLog: > > * parser.cc (cp_parser_template_name): Repeat lookup of > TYPE_DECLs. > > gcc/testsuite/ChangeLog: > > * g++.dg/parse/template-keyword3.C: New test. > * g++.dg/parse/template-keyword4.C: New test. > --- > gcc/cp/parser.cc | 5 ++++- > gcc/testsuite/g++.dg/parse/template-keyword3.C | 12 ++++++++++++ > gcc/testsuite/g++.dg/parse/template-keyword4.C | 17 +++++++++++++++++ > 3 files changed, 33 insertions(+), 1 deletion(-) > create mode 100644 gcc/testsuite/g++.dg/parse/template-keyword3.C > create mode 100644 gcc/testsuite/g++.dg/parse/template-keyword4.C > > diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc > index 03d99aba13e..02c34bf964e 100644 > --- a/gcc/cp/parser.cc > +++ b/gcc/cp/parser.cc > @@ -18681,7 +18681,10 @@ cp_parser_template_name (cp_parser* parser, > return error_mark_node; > } > else if ((!DECL_P (decl) && !is_overloaded_fn (decl)) > - || TREE_CODE (decl) == USING_DECL) > + || TREE_CODE (decl) == USING_DECL > + /* cp_parser_template_id can only handle some TYPE_DECLs. */ > + || (TREE_CODE (decl) == TYPE_DECL > + && TREE_CODE (TREE_TYPE (decl)) != TYPENAME_TYPE)) > /* Repeat the lookup at instantiation time. */ > decl = identifier; > } > diff --git a/gcc/testsuite/g++.dg/parse/template-keyword3.C b/gcc/testsuite/g++.dg/parse/template-keyword3.C > new file mode 100644 > index 00000000000..59fe0fc180b > --- /dev/null > +++ b/gcc/testsuite/g++.dg/parse/template-keyword3.C > @@ -0,0 +1,12 @@ > +// PR c++/104608 > + > +class Parameter; > +template class Function > +: public R > +{ > + Function(); > +}; > +template > +Function::Function() { > + this->template Parameter(); > +} > diff --git a/gcc/testsuite/g++.dg/parse/template-keyword4.C b/gcc/testsuite/g++.dg/parse/template-keyword4.C > new file mode 100644 > index 00000000000..c688094bcf2 > --- /dev/null > +++ b/gcc/testsuite/g++.dg/parse/template-keyword4.C > @@ -0,0 +1,17 @@ > +// PR c++/104608 > +// { dg-do compile { target c++11 } } > + > +class S; > +using Parameter = S; > +typedef S Parameter2; > + > +template class Function > +: public R > +{ > + Function(); > +}; > +template > +Function::Function() { > + this->template Parameter(); > + this->template Parameter2(); > +} > > base-commit: 4a1c20df82c9e14478d79fbe1ae9690a36285ac1