Quantcast
Channel: Active questions tagged gcc - Stack Overflow
Viewing all articles
Browse latest Browse all 22145

Uniform initialization of non-copiable class data member cause to gcc error

$
0
0

Suppose we have this code:

class A {
public:
    A() = default;    
    A(const A&) = delete;
    ~A() = default;
};

class B {
public:    
    B() : a{} { }    
    A a[1];
};

int main() 
{
    B b;
}

This code compiles on latest GCC 9.2, Clang 9.2, and MSVC 19.22.

But when I change A default destructor to ~A() { } GCC returns error use of deleted function 'A::A(const A&)'. Clang and MSVC still compile.

When I write the copy constructor of A, GCC compiles, but at runtime this constructor was never called. What does GCC need the copy constructor for? Is it GCC bug? (I've tried about all GCC versions on GodBolt.org, same error.)


Viewing all articles
Browse latest Browse all 22145

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>