c++ - typename, type members and non-type members: is it valid code? -


consider following code:

struct s {     struct type {};     type type; };  int main() {       typename s::type t;     (void) t; } 

apart fact far being idea, experimenting after having read question here on so.
found snippet above compiled no errors gcc , rejected clang 3.9 following error:

error: typename specifier refers non-type member 'type' in 's'

i suspect clang right in case , gcc wrong (actually, i'm opening issue latter).
right conclusion or valid use of typename?


note: i'm not asking how solve it, know how that. i'm asking if code valid or not.

[temp.res]/4:

the usual qualified name lookup used find qualified-id in presence of typename.

that is, unlike case elaborated-type-specifiers, name lookup in case not ignore non-type names.

[temp.res]/3:

if qualified-id in typename-specifier not denote type or class template, program ill-formed.

so program in question ill-formed.

[temp.res]/4 has example this:

struct {   struct x { };   int x; }; struct b {   struct x { }; }; template<class t> void f(t t) {   typename t::x x; } void foo() {   a;   b b;   f(b);             // ok: t::x refers b::x   f(a);             // error: t::x refers data member a::x not struct a::x } 

Comments

Popular posts from this blog

asynchronous - C# WinSCP .NET assembly: How to upload multiple files asynchronously -

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -