This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/18126] New: sizeof compound-literal not parsed correctly
- From: "jsm28 at gcc dot gnu dot org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 24 Oct 2004 11:45:15 -0000
- Subject: [Bug c++/18126] New: sizeof compound-literal not parsed correctly
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
The C++ parser fails to parse sizeof compound-literal correctly. For example,
int x = sizeof (int) { 1 };
receives the error
t.C:1: error: expected %<,%> or %<;%> before '{' token
As shown in the grammar for GNU extensions in comments in cp/parser.c,
compound literals are considered postfix-expressions as they are in C99,
so they are valid arguments to sizeof. Just as the parser deals with
cast-expressions beginning with a parenthesised type name being either
casts or compound literals, so it needs to avoid committing too early
to a particular parse in the case of sizeof. My new C parser handles
this case correctly, as has the old one since
2001-01-24 Joseph S. Myers <jsm28@cam.ac.uk>
* c-parse.in (cast_expr): Move compound literals from here ...
(primary): ... to here. Use standard terminology "compound
literal" instead of "constructor expression".
The same issue applies to alignof as applies to sizeof. Since the C++
parser - unlike the C parser and the pre-3.4 C++ parser - accepts
general unary expressions as typeof operands (despite the ambiguity)
rather than just parenthesised expressions, it also applies to typeof.
--
Summary: sizeof compound-literal not parsed correctly
Product: gcc
Version: 4.0.0
Status: UNCONFIRMED
Severity: normal
Priority: P2
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: jsm28 at gcc dot gnu dot org
CC: gcc-bugs at gcc dot gnu dot org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18126