Fix false warnings with readonly atomics
Some checks failed
build and test / test-x86_64-linux (push) Has been cancelled
build and test / test-x86_64-osx (push) Has been cancelled
build and test / test-aarch64-osx (push) Has been cancelled
build and test / test-x86_64-win32 (push) Has been cancelled
build and test / test-i386-win32 (push) Has been cancelled
build and test / test-armv7-linux (push) Has been cancelled
build and test / test-aarch64-linux (push) Has been cancelled
build and test / test-riscv64-linux (push) Has been cancelled

Code like:

    #include <stdatomic.h>
    _Atomic const int ai; int aiGet(void){ return atomic_load(&ai); }

has been raising "warning: assignment of read-only location".

This is due to `__typeof__ (*ptr) tmp;` not rvalue-converting the target
type.
This commit is contained in:
Petr Skocik 2026-04-28 08:40:53 +02:00
parent 5675177b7f
commit b39da9f6fa

View File

@ -100,7 +100,7 @@ typedef struct {
__val; })
#define atomic_load_explicit(object, order) \
({ __typeof__ (object) ptr = (object); \
__typeof__ (*ptr) tmp; \
__typeof__ ((void)0,*ptr) tmp; \
__atomic_load (ptr, &tmp, (order)); \
tmp; \
})