This might just be a "vocabulary issue", but there is something I don't get with rvalue references and pass by value.
If I have a code like this (ideone it)
struct Foo
{
Foo() { printf("Ctor\n"); }
Foo(const Foo& other) { printf("Copy\n"); }
Foo(Foo&& other) { printf("Move\n"); }
~Foo() { printf("Dtor\n"); }
};
void DoFoo(Foo foo) { printf("Foo\n"); }
int main()
{
Foo foo;
DoFoo(foo);
DoFoo(Foo{});
return 0;
}
it will give me this output (ideone result copy pasted)
Ctor 0x96eaa10 0
Copy 0x96eaa20 0
Foo 0x96eaa20 0
Dtor 0x96eaa20
Ctor 0x96eaa20 1
Foo 0x96eaa20 1
Dtor 0x96eaa20
Dtor 0x96eaa10
What I don't understand is, according to many stackoverflow answers, like here or here, the move constructor should be called for the DoFoo(Foo{})
, but it's clearly not, and the behaviour is the same with or without a Foo
move constructor.
Even replacing DoFoo(Foo foo)
by DoFoo(Foo&& foo)
does not force the call to the move constructor.
So, is it just a vocabulary issue when using moved in these particular case ? Is it a GCC particular behaviour? or anything else ?