https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93816
Bug ID: 93816 Summary: invalid typedef name with class key accepted Product: gcc Version: 10.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: msebor at gcc dot gnu.org Target Milestone: --- The second typedef in the test case below is invalid for the same reason as the first but only the first one is diagnosed and rejected. The second one is silently accepted and has been since at least GCC 4.1. $ cat t.C && gcc -S -Wall -Wextra -Wpedantic t.C typedef struct { } A; template <int> struct B { typedef struct { } C; }; typedef struct A A2; // correctly rejected typedef struct B<0>::C C2; // incorrectly accepted t.C:4:16: error: using typedef-name ‘A’ after ‘struct’ 4 | typedef struct A A2; // correctly rejected | ^ t.C:1:20: note: ‘A’ has a previous declaration here 1 | typedef struct { } A; | ^ Clang (and ICC) diagnose both: t.C:4:16: error: typedef 'A' cannot be referenced with a struct specifier typedef struct A A2; ^ t.C:1:20: note: declared here typedef struct { } A; ^ t.C:5:22: error: typedef 'C' cannot be referenced with a struct specifier typedef struct B<0>::C C2; ^ t.C:2:46: note: declared here template <int> struct B { typedef struct { } C; }; ^ 2 errors generated.