https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79561

--- Comment #1 from Marc Mutz <marc.mutz at kdab dot com> ---
For a moment, I thought it was about std::atomic, but a simple

    template <class T> container { T t; }

instead of std::atomic<T> produces the same result.

So it seems like the = default ctor is the problem. If I remove all special
member functions, the guards disappear: https://godbolt.org/g/oZlR3o

====BEGIN====
#include <atomic>
#include <type_traits>

template <typename T>
struct container { T i; };

template <typename T>
class BasicAtomic
{
public:
        container<T> v;
#if 0
        BasicAtomic() = default;
        constexpr BasicAtomic(T t) noexcept : v{t} {}
        BasicAtomic(const BasicAtomic&) = delete;
        BasicAtomic &operator=(const BasicAtomic &) = delete;
        BasicAtomic &operator=(const BasicAtomic &) volatile = delete;
 #endif
};

static_assert(std::is_pod<BasicAtomic<int>>::value, "oops");

static BasicAtomic<int> s_dyn;

int f(const char *str) {
        while (*str++)
        ++s_dyn.v.i;
        return s_dyn.v.i;
}

int f_dynamic_init(const char *str) {
        static BasicAtomic<int> counter;
        while (*str++)
        ++counter.v.i;
        return counter.v.i;
}

int f_static_init(const char *str) {
        static BasicAtomic<int> counter = {0};
        while (*str++)
        ++counter.v.i;
        return counter.v.i;
}
====END====

Reply via email to