https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84186
Bug ID: 84186 Summary: nested template qualified-id not parsed correctly Product: gcc Version: 7.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: smw at gcc dot gnu.org Target Milestone: --- OK, bear with me on this one, but it appears like a nested qualified-id that is a simple-template-id confuses the parser, or something. Here's some code. template<char k> struct N { struct S1 { // not a template class typedef short X; template<char p> struct S11 { int a[sizeof(typename N<k>::S1::X*)]; // OK }; }; template<class P> struct S2 { // woah, a class template typedef short X; template<char p> struct S21 { int a[sizeof(typename N<k>::S2<P>::X*)]; // not OK }; }; }; That snippet gets accepted by ICC, MSVC, clang, and pretty much every other compiler I tested on, bug GCC (all versions, up to and including 8.0.1 20180202) reject it [-std=c++14 -O0 -Wall -pedantic -fdiagnostics-generate-patch] with the following diagnostic output. <source>:14:45: error: 'typename N<k>::S2' names 'template<char k> template<class P> struct N<k>::S2', which is not a type int a[sizeof(typename N<k>::S2<P>::X*)]; // not OK ^ <source>:14:41: error: 'typename N<k>::S2' names 'template<char k> template<class P> struct N<k>::S2', which is not a type int a[sizeof(typename N<k>::S2<P>::X*)]; // not OK ^~~~~ <source>:14:46: error: expected '(' before '::' token int a[sizeof(typename N<k>::S2<P>::X*)]; // not OK ^~ ( <source>:14:46: error: expected ')' before '::' token int a[sizeof(typename N<k>::S2<P>::X*)]; // not OK ~ ^~ ) <source>:14:52: error: expected ']' before ';' token int a[sizeof(typename N<k>::S2<P>::X*)]; // not OK ^ ] --- <source> +++ <source> @@ -11,7 +11,7 @@ typedef short X; template<char p> struct S21 { - int a[sizeof(typename N<k>::S2<P>::X*)]; // not OK + int a[sizeof(typename N<k>::S2<P>()::X*)]]; // not OK }; }; }; Compiler returned: 1