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

            Bug ID: 108079
           Summary: -Wunused-variable gives misleading duplicate warning
                    for unused static local variable
           Product: gcc
           Version: 13.0
            Status: UNCONFIRMED
          Keywords: diagnostic
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: stephenheumann at gmail dot com
  Target Milestone: ---

For this program:

int main(void) {
        static int x;
}

gcc -Wunused-variable reports:

<source>: In function 'main':
<source>:2:20: warning: unused variable 'x' [-Wunused-variable]
    2 |         static int x;
      |                    ^
<source>: At top level:
<source>:2:20: warning: 'x' defined but not used [-Wunused-variable]

These two warnings are about the same thing, except the second one is
incorrectly labeled "At top level." There should just be one warning, without
"At top level."

C++ does the same thing, except it says "At global scope" instead of "At top
level."

This seems to be a regression that occurred in GCC 6: 5.4 just gives one
warning, but 6.1 also gives the extra one with "At top level."

Reply via email to