A few days ago I wrote something like the following:
struct A { std::atomic_bool b = false; };
Compiled in Visual Studio 2015 Update 3 with its VC ++ 2015 compiler, nothing bad happened.
Now I recompiled the same with GCC (5.4.0) on Ubuntu and got an error:
using the remote function 'std :: atomic :: atomic (const std :: atomic &)
I got the same error on ideone , installed on C ++ 14 (not sure which version of the compiler it uses).
Of course, when changing the code to the following, the problem with gcc was fixed:
struct A { std::atomic_bool b { false }; };
My questions:
1. Who is right (compatible with C ++ 11) here, VC ++ or GCC? It seems that VC ++ calls the constructor from bool, and GCC calls the copy constructor (is deleted).
2. For the default initializing atom in the class declaration, uniform initialization (above) of the correct / preferred method? Or should I use the ATOMIC_VAR_INIT (ugh!) Macro instead?
struct A { std::atomic_bool b = ATOMIC_VAR_INIT(false); };
c ++ gcc c ++ 11 stdatomic visual-c ++ - 2015
roalz
source share