[libc++] atomic_ref implementation does not support const qualified types or volatile types.
Godbolt links for the compile errors for const and volatile qualified ints. libc++ https://godbolt.org/z/nv854jbzf
Same cases but compilation succeeds. libstdc++ equivalent https://godbolt.org/z/4YoGWaK4h
Looking at atomic ref implementation, seems like the root cause is when declaring the buffer for the atomic builtin to write the value to(e.g. load), the buffer's type is same as the type that instantiated the atomic_ref tempalte.
Please be sure to include the LLVM revision of both the compiler and the libc++ headers being used directly in the bug report. (For the Fuchsia Toolchain, the clang --version output has an LLVM revision in it and the libc++ you're getting is from that same revision.) Also please make sure to include actual reproducer cases and error output directly in the bug report. It's not a good idea to presume that external links will be usable forever, and this bug database needs to preserve complete history of what the issues were.
Template instantiation for volatile/const qualified types fails to compil, compiler version, sample code and compiler output provided below. Compiler Flags:
-std=c++20 -stdlib=libc++
Full Compiler Version:
clang version 19.0.0git (https://github.com/llvm/llvm-project.git db9ac92501509ce02ed188bb20a5211a9f29d5d3)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /opt/compiler-explorer/clang-trunk-20240716/bin
Sample Code:
// Type your code here, or load an example.
#include <type_traits>
#include <atomic>
int main(int, char**) {
// This works on libstdc++ and doesnt on libc++
volatile int b= 2;
std::atomic_ref<volatile int> a(b);
auto v = a.load();
const int c= 2;
std::atomic_ref<const int> d(c);
auto e = d.load();
return v == b && c == e ? 0 : -1;
}
Compiler Output
<Compilation failed>
# For more information see the output window
x86-64 clang (trunk) - cached
In file included from <source>:5:
In file included from /opt/compiler-explorer/clang-trunk-20240716/bin/../include/c++/v1/atomic:602:
/opt/compiler-explorer/clang-trunk-20240716/bin/../include/c++/v1/__atomic/atomic_ref.h:133:27: error: cannot initialize a parameter of type 'int *' with an lvalue of type 'volatile int *'
133 | __atomic_load(__ptr_, __ret, std::__to_gcc_order(__order));
| ^~~~~
<source>:12:16: note: in instantiation of member function 'std::__atomic_ref_base<volatile int>::load' requested here
12 | auto v = a.load();
| ^
In file included from <source>:5:
In file included from /opt/compiler-explorer/clang-trunk-20240716/bin/../include/c++/v1/atomic:602:
/opt/compiler-explorer/clang-trunk-20240716/bin/../include/c++/v1/__atomic/atomic_ref.h:133:27: error: cannot initialize a parameter of type 'int *' with an lvalue of type 'const int *'
133 | __atomic_load(__ptr_, __ret, std::__to_gcc_order(__order));
| ^~~~~
<source>:16:16: note: in instantiation of member function 'std::__atomic_ref_base<const int>::load' requested here
16 | auto e = d.load();
| ^
2 errors generated.
Compiler returned: 1
Duplicate of 94879