https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102965
Bug ID: 102965 Summary: C11 atomic functions accept incompatible arguments Product: gcc Version: 12.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: --- In 7.17.1 Introduction to atomics, the C standard specifies that: -5- In the following synopses: — An A refers to an atomic type. — A C refers to its corresponding non-atomic type. The synopsis of atomic_compare_exchange listed in 7.17.7.4 The atomic_compare_exchange generic functions, looks like so: _Bool atomic_compare_exchange_strong(volatile A *object, C *expected, C desired); I.e., the function is provided for arguments of corresponding types with the only difference being that the object pointer points to an atomic type. No other signatures are provided and so the call to atomic_compare_exchange_strong in the test case below is invalid and should be diagnosed: $ cat x.c && gcc -S -Wall -Wextra -Wpedantic x.c #include <stdatomic.h> _Atomic long x; long long y, z; void f (void) { atomic_compare_exchange_strong (&x, &y, z); // should be diagnosed } Clang issues the obligatory diagnostic as expected: .c:8:39: warning: incompatible pointer types passing 'long long *' to parameter of type 'long *' [-Wincompatible-pointer-types] atomic_compare_exchange_strong (&x, &y, z); // should be diagnosed ^~ /usr/lib64/clang/7.0.1/include/stdatomic.h:140:112: note: expanded from macro 'atomic_compare_exchange_strong' ...desired) __c11_atomic_compare_exchange_strong(object, expected, desired... ^~~~~~~~ 1 warning generated.