0
class C
{
public:
    C()
    {
        std::cout << "C()" << std::endl;
    }
    C(C &&c)
    {
        std::cout << "C(C &&)" << std::endl;
    }
};

int main()
{
    C c = C();
}

I've assumed this would print
C()
C(C &&)
since C() creates a temporary object (rvalue), but this actually prints only
C()
in MSVC. Is this because of some kind of optimization?

vbstb
  • 1,261
  • 1
  • 10
  • 14
  • 1
    Yes, the compiler removes the temporary object entirely when a temporary object is created just to get copied. – DimChtz Jul 31 '17 at 00:13
  • thanks, you are right. It was also on [cppreference](http://en.cppreference.com/w/cpp/language/value_initialization) @DimChtz – vbstb Jul 31 '17 at 00:30

0 Answers0