[Bug c++/12581] [3.4 Regression ] gcc rejects typeof use for the return type

ehrhardt at mathematik dot uni-ulm dot de gcc-bugzilla@gcc.gnu.org
Thu Oct 16 16:14:00 GMT 2003


PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12581



------- Additional Comments From ehrhardt at mathematik dot uni-ulm dot de  2003-10-16 16:13 -------

The testcase basically reduces to:

int f();
__typeof__ (f)() x;

Depending on the priority of the __typeof__ operator relative to the
postfix () operator this is valid or not. The two posibilities are:
(A) declare x as int ( == __typeof__ (f ()) )
(B) get type of f (function returning int) and try to apply the postfix
   () to this which is impossible.

(A) would make __typeof__ similar to sizeof, (B) would make it similar to
typeid in C++. The downside of (A) (this is what we currently do) is that
some potentially useful applications of __typeof__ are impossible, e.g.
the one in the original report or this one which is similar:

int f ();
__typeof__ (f()) (*x) (void);

where we try do declare x as a pointer to a function returning int.
However, this is rejected, because due to the higher priority of ()
it is parsed as

__typeof__ ( (f()) (*x) (void) );

i.e. we try to get the type of the invalid unary expression
(f()) (*x) (void) and do nothing with the result. Note that it
is impossible to get the desired result by placing parentheses
in this declaration.

IMHO, this needs a language lawyer. A work around is of course to
use a typedef.

    regards  Christian



More information about the Gcc-bugs mailing list