Can automatic use of parsers use a prototype function?

This question arose because of the impossibility of using uniform initialization syntax with the auto keyword, because it treats it as std::initializer_list<T> (explanation in the comments here ).

Take the following code example:

 class X { }; int x( X() ); // function prototype (1) auto x( X() ); // copy/move construction of an X, function prototype or compile-time error? 

What does the compiler do with auto x ?

Reasoning for every opportunity:

Copy / move construction: I see that this is the correct behavior because (1) is seen as a kind of defect.

Function prototype: It seems unlikely as there is no return type of return.

Compilation error:. If the compiler analyzes this as a function prototype, this may lead to a compile-time error due to the lack of a return type.

What does the C ++ 0x standard say, should this be interpreted as?

+7
source share
1 answer

I get

 error: 'x' function uses 'auto' type specifier without late return type 

The compiler is expecting something like

 auto x( X() ) -> int; 

which would be equivalent to line 2.

+6
source

All Articles