GCC Bugzilla – Bug 56011 [C++11] std::atomic<bool> and std::atomic_bool miss volatile assignment operator overload Last modified: 2013-02-27 00:58:28 UTC
Using gcc 4.8.0 trunk the following program - compiled with the flags
-pedantic-errors -std=c++11 -Wall
is rejected:
//----------------------------------
#include <atomic>
int main() {
  volatile std::atomic<bool> ab1;
  ab1 = true;
  volatile std::atomic_bool ab2;
  ab2 = true;
//----------------------------------
"main.cpp||In function 'int main()':|
main.cpp|5|error: ambiguous overload for 'operator=' (operand types are 'volatile std::atomic<bool>' and 'bool')|
main.cpp|5|note: candidates are:|
[..]gcc\include\c++\4.8.0\atomic|485|note: std::atomic<bool>& std::atomic<bool>::operator=(const std::atomic<bool>&) volatile <deleted>|
[..]gcc\include\c++\4.8.0\atomic|64|note: std::atomic_bool& std::atomic_bool::operator=(const std::atomic_bool&) volatile <deleted>|
main.cpp|7|error: use of deleted function 'std::atomic_bool& std::atomic_bool::operator=(const std::atomic_bool&) volatile'|
[..]gcc\include\c++\4.8.0\atomic|64|error: declared here|
The problem is due to the missing overload (part of the specification):
bool operator=(bool __i) volatile noexcept;
PR libstdc++/56012 * include/bits/atomic_base.h (atomic_flag): Fix narrowing conversion. * testsuite/29_atomics/atomic/operators/56012.cc: New. PR libstdc++/56011 * include/std/atomic (atomic<bool>::operator=(bool) volatile): Add missing overload. * testsuite/29_atomics/atomic/operators/56011.cc: New. Added: trunk/libstdc++-v3/testsuite/29_atomics/atomic/operators/56011.cc trunk/libstdc++-v3/testsuite/29_atomics/atomic_flag/cons/56012.cc Modified: trunk/libstdc++-v3/ChangeLog trunk/libstdc++-v3/include/bits/atomic_base.h trunk/libstdc++-v3/include/std/atomic PR libstdc++/56012 * include/bits/atomic_base.h (atomic_flag): Fix narrowing conversion. * testsuite/29_atomics/atomic/operators/56012.cc: New. PR libstdc++/56011 * include/std/atomic (atomic<bool>::operator=(bool) volatile): Add missing overload. * testsuite/29_atomics/atomic/operators/56011.cc: New. Added: branches/gcc-4_7-branch/libstdc++-v3/testsuite/29_atomics/atomic/operators/56011.cc branches/gcc-4_7-branch/libstdc++-v3/testsuite/29_atomics/atomic_flag/cons/56012.cc Modified: branches/gcc-4_7-branch/libstdc++-v3/ChangeLog branches/gcc-4_7-branch/libstdc++-v3/include/bits/atomic_base.h branches/gcc-4_7-branch/libstdc++-v3/include/std/atomic