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

            Bug ID: 99588
           Summary: variable set but not used warning on static _Atomic
                    assignment
           Product: gcc
           Version: 11.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: godmar at gmail dot com
  Target Milestone: ---

A student shared this program with me:

#include <stdio.h>
#include <stdatomic.h>

void test() {
    static _Atomic int x = 0;
    printf("%d\n", x += 1);
}

int main(int argc, char **argv) {
    for(int i = 0; i < 10; i++) {
        test();
    }
}

which on the current x86_64 trunk (and earlier versions) as per godbolt yields
a warning:

<source>: In function 'test':
<source>:5:24: warning: variable 'x' set but not used
[-Wunused-but-set-variable]
    5 |     static _Atomic int x = 0;
      |                        ^
Compiler returned: 0

If the _Atomic modifier is removed, the warning disappears. Is this kosher?

Reply via email to