C++ standard says (12.8/9):
If the definition of a class
X
does not explicitly declare a move constructor, one will be implicitly declared as defaulted if and only if
X
does not have a user-declared copy constructor,X
does not have a user-declared copy assignment operator,X
does not have a user-declared move assignment operator, andX
does not have a user-declared destructor.
But the following code (compiled with clang++ 3.8.0 and g++ 6.3.0) gives an empty output:
#include <iostream>
struct Foo
{
Foo() = default;
Foo(const Foo&)
{
std::cout << "Copy constructor" << std::endl;
}
};
int main()
{
Foo foo{Foo{}};
(void)foo;
}
Is it a problem in clang++ and g++?
Upd. As @Piotr Skotnicki noted in comments a copy elision takes place here. The command-line key -fno-elide-constructors
disables it for constructors in clang++ and g++.