13

I've been able to find multiple conversations about this in the past (e.g. here), but such conversations are from quite a while ago. The code I have a question about is:

#include <utility>
#include <iostream>

struct Foo
{
    Foo() = default;
    Foo(const Foo &o)
    {
        std::cout << "copy" << std::endl;
    }
    Foo(Foo &&o)
    {
        std::cout << "move" << std::endl;
    }
};

struct Bar
{
    Foo foo;
};

int main(void)
{
    Bar a;
    Bar b(a);
    Bar c(std::move(a));
}

If you execute the code in Visual Studio 2013 (Update 3), it prints out "copy" for both cases. If the standard hasn't changed since the answer in the link above, then the output should be "copy" followed by "move." Ideone seems to give the correct output. Is this just something that Visual Studio hasn't implemented yet, or is there something missing in my code? I know that you cannot mark move constructors as default, but that does not imply that the compiler does not support generating default move constructors all-together.

Community
  • 1
  • 1
Duncan
  • 980
  • 6
  • 17

1 Answers1

20

I know that you cannot mark move constructors as default, but that does not imply that the compiler does not support generating default move constructors all-together

Unfortunately, that's exactly what that means. VS2013 does not support implicit generation of move constructors and move assignment operators. If it did, they wouldn't really have a reason to disallow the = default syntax, especially since you're allowed to do that for the copy constructor and assignment operator.

Quoting MSDN: Support For C++11 Features (Modern C++)

"Rvalue references v3.0" adds new rules to automatically generate move constructors and move assignment operators under certain conditions. However, this is not implemented in Visual C++ in Visual Studio 2013, due to time and resource constraints.

Praetorian
  • 106,671
  • 19
  • 240
  • 328
  • 1
    That's disappointing. I also found [this chart](http://blogs.msdn.com/b/somasegar/archive/2013/06/28/cpp-conformance-roadmap.aspx), so it looks like vNext should have it implemented. Looks like I have some code to go modify now... – Duncan Oct 27 '14 at 05:13
  • 17
    This sucks sucks sucks. – Samuel Danielson Dec 21 '14 at 06:14
  • 1
    @tomi.lee.jones That's not true, look at [this table](http://blogs.msdn.com/b/vcblog/archive/2014/11/17/c-11-14-17-features-in-vs-2015-preview.aspx). The feature in question is labeled *Defaulted and deleted functions*. The example shown in the question outputs *move* for the last line on VS2015 Preview. – Praetorian Jun 08 '15 at 22:11
  • @Praetorian I've seen this table and you're right, the error was on my part (VS2015 RC). – tomi.lee.jones Jun 09 '15 at 00:11