https://gcc.gnu.org/bugzilla/show_bug.cgi?id=119654
Bug ID: 119654
Summary: name lookup after `typename` incorrectly ignores
non-type non-namespace names
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: richard-gccbugzilla at metafoo dot co.uk
Target Milestone: ---
Testcase:
template<typename T> struct X { typedef int type; };
struct Y { typedef int type; };
void f() {
int X, Y;
X<int>::type x1;
typename X<int>::type x2;
Y::type y;
}
struct Z : X<int>, Y {
int X, Y;
};
void g() {
Z::X<int>::type x1;
typename Z::X<int>::type x2;
Z::Y::type y;
}
Here, every compiler agrees that in both f and g, x1 is ill-formed because `X`
names the int, and y is valid because name lookup for `Y` in `Y::` ignores
names other than types and namespaces.
However, only GCC accepts x2, because GCC appears to apply the "identifier
before ::" name lookup rule to names following `typename` too. Or perhaps it
forms a simple-template-id, then notices the following `::`, then applies the
"identifier before ::" name lookup rule despite a simple-template-id not being
an identifier. That behavior makes some sense, given that the name can only
name a type or namespace in valid code, but it's wrong -- the standard is quite
clear on this, and all other compilers reject.
See [temp.res.general]/3:
> A typename-specifier denotes the type or class template denoted by the
> simple-type-specifier ([dcl.type.simple]) formed by omitting the keyword
> typename.
> [Note 2: The usual qualified name lookup ([basic.lookup.qual]) applies even
> in the presence of typename. — end note]
GCC doesn't diagnose even under `-pedantic-errors`, so I assume this is a bug
rather than an intentional extension.