https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101316
Bug ID: 101316 Summary: [[maybe_unused]] to the right of array size accepted Product: gcc Version: 11.1.0 Status: UNCONFIRMED Keywords: diagnostic Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: gcc at alanwu dot email Target Milestone: --- GCC 11.1.0 and trunk accepts [[maybe_unused]] in the following in a way the standard doesn't seem to allow: void func() { int one, two[2] [[maybe_unused]]; } $ g++ -c -std=c++20 -Wall test.cc test.cc: In function ‘void func()’: test.cc:2:13: warning: unused variable ‘one’ [-Wunused-variable] 2 | int one, two[2] [[maybe_unused]]; | ^~~ There is no unused variable warning about `two` because it accepts the attribute. The declaration for `two` matches the form outlined in [dcl.array]p3 which says the attribute appertains to the array type. [dcl.attr.unused]p2 doesn't allow [[maybe_unused]] to apply to type entities. [dcl.attr.grammar]p5 says that when an attribute appertains to an entity that it's not allowed to apply to, the program is ill-formed. Should g++ reject the program in this case? https://godbolt.org/z/EWr4q63cT