http://jaredgrubb.blogspot.com/2013/05/c11-quirks-in-defaulted-functions.html
According to answers from the stack overflow it comes out that POD objects cannot be used with default constructors if you wish to create const instance of them. And it makes sense, as the const object cannot be changed in future.
The funny part is when you use `= default` outside of class body everything's fine.
Interestingly Clang compiler is again closer to the standard than gcc. It doesn't compile following code, whereas gcc does.
struct A { A() = default; } int main(int, char) { const A a; }
Thanks to Jonathan Wakely it turned out that Clang behavior is the proper one. The C++ standard states:
"A special member function is user-provided if it is user-declared and not explicitly defaulted on its first declaration. A user-provided explicitly-defaulted function (i.e., explicitly defaulted after its first declaration) is defined at the point where it is explicitly defaulted; if such a function is implicitly defined as deleted, the program is ill-formed." [N3242, 8.4.2/4]
Brak komentarzy:
Prześlij komentarz