https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99272
Bug ID: 99272 Summary: False positive -Wredundant-tags warning when reusing a name Product: gcc Version: 10.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: headch at gmail dot com Target Milestone: --- $ cat test.cpp struct foo { int x; }; struct bar { struct foo foo; }; $ g++-10.2.0 -Wall -Wextra -Wredundant-tags -std=c++2a -c test.cpp test.cpp:6:2: warning: redundant class-key ‘struct’ in reference to ‘struct foo’ [-Wredundant-tags] 6 | struct foo foo; | ^~~~~~ | ------ But this is not redundant. Removing the word “struct” results in a compile error: $ g++-10.2.0 -Wall -Wextra -Wredundant-tags -std=c++2a -c test.cpp test.cpp:6:6: error: declaration of ‘foo bar::foo’ changes meaning of ‘foo’ [-fpermissive] 6 | foo foo; | ^~~ test.cpp:1:8: note: ‘foo’ declared here as ‘struct foo’ 1 | struct foo { | ^~~ Therefore I think -Wredundant-tags should not generate a warning in this situation (the tag is not redundant).