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

mmitchel at gcc dot gnu dot org gcc-bugzilla@gcc.gnu.org
Wed Nov 12 16:14:00 GMT 2003


------- Additional Comments From mmitchel at gcc dot gnu dot org  2003-11-12 16:14 -------
There are two pieces of code in this PR; comment #1 and comment #2.

(1) In comment #2, GCC does not accept the code, either.  That's because:

  typedef int (F)();
  F() x;

is not syntactically valid either.

(3) In the example in comment #1, the problem is more complex.  The "typeof"
keyword, like the "sizeof" keyword, can be used in two alternative productions:

sizeof type-id
sizeof unary-expression

In comment #1, it is the second production which is used.  Note that this second
production is *not* "sizeof (unary-expression)"; the unary-expression is not
parenthesized.  

One alternative for a unary-expression is a postfix-expression.  

A postfix-expression can have the form "x (...)".  

That is the syntactic form of the line in comment #1: (Just...) (....).  The
parser becomes unhappy when it sees "bar::*" because "*" is not a valid identifier.

(This case is analogous to "sizeof f ()" which is valid C/C++.)

To try to recover from the case where the arguments to the function call are not
valid would require a considerable amount of code and a slower parser.

-- 


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



More information about the Gcc-bugs mailing list