[Bug c/95378] New: __atomic_load will write to objects of cv-qualified types

redi at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Wed May 27 22:08:59 GMT 2020


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

            Bug ID: 95378
           Summary: __atomic_load will write to objects of cv-qualified
                    types
           Product: gcc
           Version: 10.0
            Status: UNCONFIRMED
          Keywords: accepts-invalid
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: redi at gcc dot gnu.org
  Target Milestone: ---

GCC happily compiles this:

void f()
{
  int i = 1;
  const int c = 0;
  __atomic_load(&i, &c, __ATOMIC_SEQ_CST);
  volatile int v = 0;
  __atomic_load(&i, &v, __ATOMIC_SEQ_CST);
  const volatile int cv = 0;
  __atomic_load(&i, &cv, __ATOMIC_SEQ_CST);
}

Clang sensibly rejects it:

af.cc:5:21: error: cannot initialize a parameter of type 'int *' with an rvalue
of type 'const int *'
  __atomic_load(&i, &c, __ATOMIC_SEQ_CST);
                    ^~
af.cc:7:21: error: cannot initialize a parameter of type 'int *' with an rvalue
of type 'volatile int *'
  __atomic_load(&i, &v, __ATOMIC_SEQ_CST);
                    ^~
af.cc:9:21: error: cannot initialize a parameter of type 'int *' with an rvalue
of type 'const volatile int *'
  __atomic_load(&i, &cv, __ATOMIC_SEQ_CST);
                    ^~~


More information about the Gcc-bugs mailing list