Copy Elision for temporaries not working

According to C++ 17, the following code should compile:


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
class MyClass
{
public:
	MyClass(const MyClass&) = delete;
	MyClass(MyClass&&) = delete;
	
};

void foo( MyClass param)
{
	
}

MyClass bar()
{
	return MyClass{};
}


namespace CopyElision
{
	void main()
	{
		foo(MyClass{});
		MyClass x = bar();
		foo(bar());
	}
}


but it complains about calling deleted functions (copy and move ctors)...

This is with Visual Studio 2019 version 16.6.2


Is it a compiler not up to date issue or is the code above illegal?


Regards,
Juan Dent
Both GCC and Clang accept the program with -std=c++17.
Ok so it is the compiler not quite at C++17!

Thanks,
Juan
You should also be getting some warnings about your main() function.

The function main() must be defined to return an int, and it must be in the global namespace.

Topic archived. No new replies allowed.