https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79695

            Bug ID: 79695
           Summary: spurious -Wunused-variable on a static global of a
                    type 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: ---

G++ (but not GCC in C mode) warns on all three variables in the program below
even though their type is declared attribute unused and thus no warning should
be issued for them.

In addition, the wording of the warning is inconsistent.  It should be the same
in both cases.  The first instance is issued by the C++ front end and the
latter two come from cgraphunit.c.

$ (set -x && cat u.c && for lang in c c++; do gcc -S -Wall -Wextra -Wpedantic
-x$lang u.c; done)
+ cat u.c
typedef int __attribute__ ((unused)) T;

static T x;

void f (void)
{
  static T y;
}

void g (void)
{
  T z;
}

+ for lang in c c++
+ gcc -S -Wall -Wextra -Wpedantic -xc u.c
+ for lang in c c++
+ gcc -S -Wall -Wextra -Wpedantic -xc++ u.c
u.c: In function ‘void f()’:
u.c:7:12: warning: unused variable ‘y’ [-Wunused-variable]
   static T y;
            ^
u.c: At global scope:
u.c:7:12: warning: ‘y’ defined but not used [-Wunused-variable]
u.c:3:10: warning: ‘x’ defined but not used [-Wunused-variable]
 static T x;
          ^

Reply via email to