https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63322
Bug ID: 63322 Summary: std::atomic<T> where T is not trivially copyable should be disabled. Product: gcc Version: 5.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: libstdc++ Assignee: unassigned at gcc dot gnu.org Reporter: roman at binarylife dot net [atomic.types.generic]: There is a generic class template atomic<T>. The type of the template argument T shall be trivially copyable (3.9). It would be helpful if std::atomic<T> disallowed wrong T because the generated code is obviously makes no sense (at least for x86_64): bar() returns a hard-coded NaN. $ cat test.cc #include <atomic> long double foo(const long double& f) noexcept; struct X { X() = default; X(X const& o) noexcept : f(foo(o.f)) {} X& operator=(X const& o) noexcept { f = foo(o.f); return *this; } long double f = foo(0); }; extern std::atomic<X> a; long double bar() { a.load().f; } $ g++ -c -O2 --save-temps -std=c++11 test.cc && echo ok ok $ cat test.s .file "test.cc" .section .text.unlikely,"ax",@progbits .LCOLDB2: .text .LHOTB2: .p2align 4,,15 .globl _Z3barv .type _Z3barv, @function _Z3barv: .LFB330: .cfi_startproc fldz subq $24, %rsp .cfi_def_cfa_offset 32 movq %rsp, %rdi fstpt (%rsp) call _Z3fooRKe fstp %st(0) movl $5, %esi movl $a, %edi call __atomic_load_16 flds .LC1(%rip) addq $24, %rsp .cfi_def_cfa_offset 8 ret .cfi_endproc .LFE330: .size _Z3barv, .-_Z3barv .section .text.unlikely .LCOLDE2: .text .LHOTE2: .section .rodata.cst4,"aM",@progbits,4 .align 4 .LC1: .long 2143289344 .ident "GCC: (GNU) 5.0.0 20140920 (experimental)" .section .note.GNU-stack,"",@progbits