http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53901

             Bug #: 53901
           Summary: [C++11] std::atomic<T> fails for type without trivial
                    default constructor and trivial destructor
    Classification: Unclassified
           Product: gcc
           Version: 4.7.1
            Status: UNCONFIRMED
          Keywords: rejects-valid
          Severity: normal
          Priority: P3
         Component: libstdc++
        AssignedTo: unassig...@gcc.gnu.org
        ReportedBy: r...@gcc.gnu.org


This fails to compile:

#include <atomic>

struct T {
    T noexcept(false) { }
    ~T noexcept(false) { }
};

std::atomic<T> a;


g++ -std=c++11 ex.cc

In file included from ex.cc:1:0:
/home/jwakely/gcc/4.x/include/c++/4.8.0/atomic: In instantiation of 'struct
std::atomic<T>':
ex.cc:16:21:   required from here
/home/wakelj/tools/Linux-f12-x86_64/4.8/include/c++/4.8.0/atomic:163:7: error:
function 'std::atomic<_Tp>::atomic() [with _Tp = T]' defaulted on its first
declaration with an exception-specification that differs from the implicit
declaration 'std::atomic<T>::atomic()'
       atomic() noexcept = default;
       ^
/home/jwakely/gcc/4.x/include/c++/4.8.0/atomic:164:7: error: function
'std::atomic<_Tp>::~atomic() [with _Tp = T]' defaulted on its first declaration
with an exception-specification that differs from the implicit declaration
'std::atomic<T>::~atomic()'
       ~atomic() noexcept = default;
       ^

I believe the only requirement on the type T is that it's trivially copyable.

The defaulted constructor and destructor in atomic<T> need to be declared in
the class then defined as deleted later.

Reply via email to