2

Given a function like:

Foo MakeFoo(const std::string& name);

we might expect the following to be move constructed, assuming a move constructor is defined for Foo, because the RHS is a temporary:

auto foo = MakeFoo("foo 1");

Does the same hold true for fields of temporaries? For example, in:

auto bar = MakeFoo("foo 2").bar;

assuming decltype(Foo::bar) has both copy and move construction defined, is it guaranteed to use one or the other, and does it depend in any way on compiler optimization level?

Scott Minor
  • 137
  • 1
  • 7

0 Answers0