https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79667
Bug ID: 79667 Summary: spurious -Wunused-variable on a local array of struct declared unused Product: gcc Version: 7.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: --- Both the C and C++ front ends issue a -Wunused-variable warning for the declaration of an unused local array of a struct declared unused. According to the documentation, attribute unused should suppress such warnings: When attached to a type (including a union or a struct), this attribute means that variables of that type are meant to appear possibly unused. GCC does not produce a warning for any variables of that type, even if the variable appears to do nothing. I'm guessing this may be because the type of the variable GCC warns on is derived from the type and not of the type itself. For arrays, I think this is overly subtle and GCC should avoid diagnosing them just like it does non-arrays. This is also what recent versions of Clang and Intel ICC do. (Both Clang and ICC used to diagnose arrays just like GCC does now but stopped some time ago.) $ (set -x && cat y.C && for lang in c c++; do gcc -S -Wall -Wextra -Wunused -Wpedantic -x$lang y.C; done) + cat y.C struct __attribute__ ((unused)) A { int i; }; void f (void) { struct A a; // no warning, ok } void g (void) { struct A a[1]; // warning, bug } + for lang in c c++ + /build/gcc-git/gcc/xgcc -B /build/gcc-git/gcc -S -Wall -Wextra -Wunused -Wpedantic -xc y.C y.C: In function ‘g’: y.C:10:12: warning: unused variable ‘a’ [-Wunused-variable] struct A a[1]; // warning, bug ^ + for lang in c c++ + /build/gcc-git/gcc/xgcc -B /build/gcc-git/gcc -S -Wall -Wextra -Wunused -Wpedantic -xc++ y.C y.C: In function ‘void g()’: y.C:10:12: warning: unused variable ‘a’ [-Wunused-variable] struct A a[1]; // warning, bug ^