Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where in the C++ standard does it state that the default constructor is not generated when the copy constructor is deleted?

The C++11 program

struct Foo {
    Foo(Foo const &) = delete;
};

int main() {
    Foo foo;
}

generates the error

$ g++ -std=c++11 junk.cpp -o junk
junk.cpp: In function 'int main()':
junk.cpp:6:9: error: no matching function for call to 'Foo::Foo()'
junk.cpp:6:9: note: candidate is:
junk.cpp:2:5: note: Foo::Foo(const Foo&) <deleted>
junk.cpp:2:5: note:   candidate expects 1 argument, 0 provided

Now, it looks like the default constructor was prevented from being generated because the copy constructor was deleted. I'm going to assume this is the expected behavior, but where in the C++ standard does it specify that the default constructor should not be generated when the copy constructor is deleted?

like image 966
wyer33 Avatar asked Dec 26 '22 03:12

wyer33


1 Answers

From N3485 §12.1 [class.ctor]/5:

If there is no user-declared constructor for class X, a constructor having no parameters is implicitly declared as defaulted (8.4).

Foo(Foo const &) = delete; is a user-declared constructor, so no default constructor is generated by the compiler.

like image 51
chris Avatar answered Mar 10 '23 12:03

chris