When compiling the following program: struct S {int z;}; typedef S* (*FuncType)(int,int); int x,y; S* a() { FuncType(a)(x,y)->z = 0; // treated as declaration return 0; } This is the result: t.cpp: In function 'S* a()': t.cpp:5: error: initializer expression list treated as compound expression t.cpp:5: error: invalid conversion from 'int' to 'S* (*)(int, int)' t.cpp:5: error: expected ',' or ';' before '->' token Shouldn't GCC examine '->' after 'FuncType(a)(x,y)' and conclude that the statement is an expression instead of a declaration ?
I think GCC is correct here.
I forgot to mention that both MSVC and Comeau compilers interpret FuncType(a)(x,y)->z = 0; as expression and compile the test program without errors.
And some bit of C++ standard wisdom: C++ 6.8p1: "To disambiguate, the whole statement might have to be examined to determine if it is an expression-statement or a declaration" And there's this example given: T(a)->m = 7; // expression-statement I think the same applies to the example I gave: T(a)(x,y)->m = 7; // should be an expression
Same problem happens with int m; int(m), m++; I think GCC is wrong rejecting this.
(In reply to comment #0) > typedef S* (*FuncType)(int,int); > int x,y; > S* a() { > FuncType(a)(x,y)->z = 0; // treated as declaration calling 'a' through a function pointer of a different type is undefined behaviour, but fixing that doesn't change the error, which I agree is wrong.