I think it's worth telling you about a similar problem that also causes problems:
struct foo { }; struct bar { bar(foo f); }; int main() {
Actually, this is a function that returns bar and takes as its first argument a pointer to a function that returns foo without arguments. This is the same as:
bar b(foo(*)());
If you want to create a bar object initialized with the default built foo, put parentheses around the argument. This makes it no longer look like a function declaration, and the compiler will interpret it the way you want:
bar b((foo()));
There are also no obvious cases where a compiler error should be raised. GCC is wrong, but Como is recovering again. Consider the following snippet
struct foo { static bool const value = false; }; int main() { int v(int(foo::value)); }
You probably expect this to take a static constant and discard it to int , initializing the variable v to 0 ? No, this will not conform to the standard, because the initializer can be interpreted as a declaration according to purely parsing, as shown below:
struct foo { static int value; };
Whenever an initializer can be interpreted as a declaration, in such a situation the whole declaration will declare a function. So, the line in main declares the next function, omitting the extra and meaningless parentheses
int v(int foo::value);
And this will cause a compiler error when parsing a function declaration, since the function parameter name may not be qualified.
source share