Is it possible to use the converting constructor rather than copy constructor to return object from a function even if there is no RVO evolved(Suppose that the compiler is not supporting any such kind of optimizations)? The point of the question is what is the C++ std having told, could anyone tell me? I got the gcc and compiled the code below with several questions in the comment either.
class A
{
public:
A(int) {};
A(int, int) {};
private:
A(const A &) = delete;
A & operator = (const A &) = delete;
};
A foo(void)
{// All the CEs below are all the same, which is 'using the deleted function 'A::A(const A&)''.
//return(0); // Not compiled.
//return(A(0)); // Not compiled. ok since the A isn't be copy-able.
//return {0}; // Compiled. Is it a bug of the compiler?
//return({0}); // Not compiled. What happened when returns in '()' implemented?
//return 0; // Not compiled. What happened when returns without '()' and '{}' implemented?
//return ({0, 0}); // Not compiled.
return {0, 0}; // Compiled. Realy??
/*
1. What are the differences in 'return 0', 'return {0}', 'return(0)' and 'return({0})'?
2. Is it any possible to do conversion from source type object 'which is 'int' in this sample' to returning type of
the function directly with only ONE constructor call even if the compiler has no any copying eliminating optimization
but full compatibility with STD? Note that the function 'foo' here has no returning object accepter.
*/
}
int main(void)
{
foo(); // Note that there is no accepter of 'A' here, it's not discussing purpose at this topic of the post.
}
// compiling with the gcc ver. 4.8.1.