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 CE9F838708D4 for ; Tue, 18 Apr 2023 12:13:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org CE9F838708D4 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=1681820007; 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: in-reply-to:in-reply-to:references:references; bh=36ON+tkpluBWN2K86z3XD235GVUmWIDfTzzore9UWOc=; b=E7H4Ou/vFP4uarlx5WqhHMPbfggd3aCIdQorSC4Igm3lFIyDPTFSwDPj2NIWKBORfB6/gV Q78PCnF4QbhzfdBTgqn2COGKxMKgx4NXfsSZt0lY5Z75zTy5Er48CrH53mswOyYhxVoQdI Nf8VyfzYPr3yzbJd88O+cUeYQNZGM2A= Received: from mail-ed1-f71.google.com (mail-ed1-f71.google.com [209.85.208.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-316-GGCt8_mEOEGzrDaelSXRyg-1; Tue, 18 Apr 2023 08:13:25 -0400 X-MC-Unique: GGCt8_mEOEGzrDaelSXRyg-1 Received: by mail-ed1-f71.google.com with SMTP id 4fb4d7f45d1cf-506b0b75731so752325a12.3 for ; Tue, 18 Apr 2023 05:13:25 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681820005; x=1684412005; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=36ON+tkpluBWN2K86z3XD235GVUmWIDfTzzore9UWOc=; b=kvqb1zM9EDVOknu343I4mBYwe2TozIjWJIlFg0OlGYYvDdQ9NgnJzKe8j44X8ac4hn UQyya+yV7FDeqDj7LDJleQr5P2sDPeX/bWvqnWaK81Zonb8w3FjLRgMxHssriUS/n4SN kTqePECytvuiiePsoH2W3lvvjUWI7Li9ufNT0OmCIKn/Fajmw06fEPzqovnvPE8s0+eW jXUYxlYmFmY5AnN6+NwEJ0m3I/n2AD8iehM93eM2t+6fZpG/jeNzt5xMl9v5TaRs8tCo WsvC9I6MD+clLsUiH632P2GO8h/oCAB8Cl4z5tJCzbq0EpSWPjJ/yL8YR8/p0hh61tlR Symg== X-Gm-Message-State: AAQBX9cF2TW2PBvhS/nDK/vwpP2wYUYV6Qa/A1q0Mv1j0DIKgNQcNUcb Ob4C6avzz6pwMcHu+b+QFKmpDOFoQ5JgfCKtzR3II2B4iS2gF03ojtWC4E5VdIAPgvj06sAoaFz d7CPE5MS7JICSuKoEWKsbG4Iow0jKO3RaDg== X-Received: by 2002:aa7:d816:0:b0:4f9:f07d:a978 with SMTP id v22-20020aa7d816000000b004f9f07da978mr2418996edq.5.1681820004797; Tue, 18 Apr 2023 05:13:24 -0700 (PDT) X-Google-Smtp-Source: AKy350YpwxABxf8QOFkTjgkU6Vc+Urok5x7CeeRsrHXmItuzcvW1mWPxjcIhq5vui1Kp8fP4qr87posocXGq4PPmtZM= X-Received: by 2002:aa7:d816:0:b0:4f9:f07d:a978 with SMTP id v22-20020aa7d816000000b004f9f07da978mr2418980edq.5.1681820004453; Tue, 18 Apr 2023 05:13:24 -0700 (PDT) MIME-Version: 1.0 References: <20230405165927.1987914-1-ppalka@redhat.com> In-Reply-To: From: Patrick Palka Date: Tue, 18 Apr 2023 08:13:13 -0400 Message-ID: Subject: Re: [PATCH] c++: 'typename T::X' vs 'struct T::X' lookup [PR109420] To: Andrew Pinski Cc: gcc-patches@gcc.gnu.org, jason@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-13.0 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: On Wed, Apr 5, 2023 at 1:36=E2=80=AFPM Andrew Pinski wr= ote: > > On Wed, Apr 5, 2023 at 10:32=E2=80=AFAM Patrick Palka via Gcc-patches > wrote: > > > > On Wed, 5 Apr 2023, Patrick Palka wrote: > > > > > r13-6098-g46711ff8e60d64 made make_typename_type no longer ignore > > > non-types during the lookup, unless the TYPENAME_TYPE in question was > > > followed by the :: scope resolution operator. But there is another > > > exception to this rule: we need to ignore non-types during the lookup > > > also if the TYPENAME_TYPE was named with a tag other than 'typename', > > > such as 'struct' or 'enum', as per [dcl.type.elab]/5. > > > > > > This patch implements this additional exception. It occurred to me t= hat > > > the tf_qualifying_scope flag is probably unnecessary if we'd use the > > > scope_type tag more thoroughly, but that requires parser changes that > > > are probably too risky at this stage. (I'm working on addressing the > > > FIXME/TODOs here for GCC 14.) > > > > > > Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK = for > > > trunk? > > > > > > PR c++/109420 > > > > > > gcc/cp/ChangeLog: > > > > > > * decl.cc (make_typename_type): Also ignore non-types during > > > the lookup if tag_type is something other than none_type or > > > typename_type. > > > * pt.cc (tsubst) : Pass class_type or > > > enum_type as tag_type to make_typename_type as appropriate > > > instead of always passing typename_type. > > > > > > gcc/testsuite/ChangeLog: > > > > > > * g++.dg/template/typename27.C: New test. > > > --- > > > gcc/cp/decl.cc | 9 ++++++++- > > > gcc/cp/pt.cc | 9 ++++++++- > > > gcc/testsuite/g++.dg/template/typename27.C | 19 +++++++++++++++++++ > > > 3 files changed, 35 insertions(+), 2 deletions(-) > > > create mode 100644 gcc/testsuite/g++.dg/template/typename27.C > > > > > > diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc > > > index 5369714f9b3..a0a20c5accc 100644 > > > --- a/gcc/cp/decl.cc > > > +++ b/gcc/cp/decl.cc > > > @@ -4307,7 +4307,14 @@ make_typename_type (tree context, tree name, e= num tag_types tag_type, > > > lookup will stop when we hit a dependent base. */ > > > if (!dependent_scope_p (context)) > > > { > > > - bool want_type =3D (complain & tf_qualifying_scope); > > > + /* As per [dcl.type.elab]/5 and [temp.res.general]/3, ignore n= on-types if > > > + the tag corresponds to a class-key or 'enum' (or is scope_type= ), or if > > > + this typename is followed by :: as per [basic.lookup.qual.gene= ral]/1. > > > + TODO: If we'd set the scope_type tag accurately on all TYPENAM= E_TYPEs > > > + that are followed by :: then we wouldn't need the tf_qualifyin= g_scope > > > + flag. */ > > > + bool want_type =3D (tag_type !=3D none_type && tag_type !=3D t= ypename_type) > > > + || (complain & tf_qualifying_scope); > > > > Here's v2 which just slightly improves this comment. I reckon [basic.l= ookup.elab] > > is a better reference than [dcl.type.elab]/5 for justifying why the > > lookup should be type-only for class-key and 'enum' TYPENAME_TYPEs. > > > > -- >8 -- > > > > PR c++/109420 > > > > gcc/cp/ChangeLog: > > > > * decl.cc (make_typename_type): Also ignore non-types during th= e > > lookup if tag_type corresponds to an elaborated-type-specifier. > > * pt.cc (tsubst) : Pass class_type or > > enum_type as tag_type to make_typename_type as appropriate > > instead of always passing typename_type. > > > > gcc/testsuite/ChangeLog: > > > > * g++.dg/template/typename27.C: New test. > > --- > > gcc/cp/decl.cc | 12 +++++++++++- > > gcc/cp/pt.cc | 9 ++++++++- > > gcc/testsuite/g++.dg/template/typename27.C | 19 +++++++++++++++++++ > > 3 files changed, 38 insertions(+), 2 deletions(-) > > create mode 100644 gcc/testsuite/g++.dg/template/typename27.C > > > > diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc > > index 5369714f9b3..772c059dc2c 100644 > > --- a/gcc/cp/decl.cc > > +++ b/gcc/cp/decl.cc > > @@ -4307,7 +4307,17 @@ make_typename_type (tree context, tree name, enu= m tag_types tag_type, > > lookup will stop when we hit a dependent base. */ > > if (!dependent_scope_p (context)) > > { > > - bool want_type =3D (complain & tf_qualifying_scope); > > + /* We generally don't ignore non-types during TYPENAME_TYPE look= up > > + (as per [temp.res.general]/3), unless > > + - the tag corresponds to a class-key or 'enum' so > > + [basic.lookup.elab] applies, or > > + - the tag corresponds to scope_type or tf_qualifying_scope i= s > > + set so [basic.lookup.qual]/1 applies. > > + TODO: If we'd set/track the scope_type tag thoroughly on all > > + TYPENAME_TYPEs that are followed by :: then we wouldn't need t= he > > + tf_qualifying_scope flag. */ > > + bool want_type =3D (tag_type !=3D none_type && tag_type !=3D typ= ename_type) > > + || (complain & tf_qualifying_scope); > > t =3D lookup_member (context, name, /*protect=3D*/2, want_type, = complain); > > } > > else > > diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc > > index 821e0035c08..09559c88f29 100644 > > --- a/gcc/cp/pt.cc > > +++ b/gcc/cp/pt.cc > > @@ -16580,9 +16580,16 @@ tsubst (tree t, tree args, tsubst_flags_t comp= lain, tree in_decl) > > return error_mark_node; > > } > > > > + /* FIXME: TYPENAME_IS_CLASS_P conflates 'union' vs 'struct' vs = 'class' > > + tags. TYPENAME_TYPE should probably remember the exact tag = that > > + was written. */ > > Yes I had a patch for that but I submitted during stage 4 of GCC 12 > and never updated again during stage 1 of GCC 13. I hope to submit it > again with updated changes post this patch. That'd be great. We could encode all possible tags using three adjacent TREE_LANG_FLAG bits I think (so just one more bit than what TYPENAME_TYPE currently uses). > > Thanks, > Andrew > > > > + enum tag_types tag > > + =3D TYPENAME_IS_CLASS_P (t) ? class_type > > + : TYPENAME_IS_ENUM_P (t) ? enum_type > > + : typename_type; > > tsubst_flags_t tcomplain =3D complain | tf_keep_type_decl; > > tcomplain |=3D tst_ok_flag | qualifying_scope_flag; > > - f =3D make_typename_type (ctx, f, typename_type, tcomplain); > > + f =3D make_typename_type (ctx, f, tag, tcomplain); > > if (f =3D=3D error_mark_node) > > return f; > > if (TREE_CODE (f) =3D=3D TYPE_DECL) > > diff --git a/gcc/testsuite/g++.dg/template/typename27.C b/gcc/testsuite= /g++.dg/template/typename27.C > > new file mode 100644 > > index 00000000000..61b3efd998e > > --- /dev/null > > +++ b/gcc/testsuite/g++.dg/template/typename27.C > > @@ -0,0 +1,19 @@ > > +// PR c++/109420 > > + > > +struct A { > > + struct X { }; > > + int X; > > +}; > > + > > +struct B { > > + enum E { }; > > + enum F { E }; > > +}; > > + > > +template > > +void f() { > > + struct T::X x; // OK, lookup ignores the data member 'int A::X' > > + enum U::E e; // OK, lookup ignores the enumerator 'B::F::E' > > +} > > + > > +template void f(); > > -- > > 2.40.0.153.g6369acd968 > > >