This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/12581] [3.4 Regression] gcc rejects typeof use for the return type
- From: "mmitchel at gcc dot gnu dot org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 12 Nov 2003 16:14:41 -0000
- Subject: [Bug c++/12581] [3.4 Regression] gcc rejects typeof use for the return type
- References: <20031011162654.12581.pinskia@gcc.gnu.org>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
------- 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