samedi 10 juillet 2021

Why does std::atomic compile from C++17 even with a deleted copy constructor?

I have a simple code:

#include <atomic>

int main()
{
    std::atomic<int> a = 0;
}

This code compiles fine with GCC 11.1.0 with -std=c++17, but fails with -std=c++14 and -std=c++11.

using a deleted function std::atomic::atomic(const std::atomic&)

Why is that? In C++17 class std::atomic still doesn't have a copy constructor. Why is this code valid for -std=c++17?

Of course I know that the preferred style is to use {}, but I'm just curious why the code above compiles fine since C++17.

Aucun commentaire:

Enregistrer un commentaire