[LLVMbugs] [Bug 20634] New: clang incorrectly parses array declarators in sizeof operand.
bugzilla-daemon at llvm.org
bugzilla-daemon at llvm.org
Tue Aug 12 10:11:45 PDT 2014
http://llvm.org/bugs/show_bug.cgi?id=20634
Bug ID: 20634
Summary: clang incorrectly parses array declarators in sizeof
operand.
Product: clang
Version: trunk
Hardware: PC
OS: Linux
Status: NEW
Severity: normal
Priority: P
Component: -New Bugs
Assignee: unassignedclangbugs at nondot.org
Reporter: nbowler at draconx.ca
CC: llvmbugs at cs.uiuc.edu
Classification: Unclassified
Consider the following C program:
#include <stdio.h>
int main(void)
{
printf("%zu\n", sizeof (struct { int a; } [2]));
return 0;
}
While unusual, there is no problem with this type name from the C
grammar productions (from n1570, but I don't believe these are
changed significantly from earlier revisions):
type-name
-> specifier-qualifier-list abstract-declarator
-> type-specifier abstract-declarator
-> struct-or-union-specifier abstract-declarator
-> struct-or-union { struct-declaration-list } abstract-declarator
-> struct { struct-declaration-list } abstract-declarator
-> struct { struct-declaration-list } direct-abstract-declarator
-> struct { struct-declaration-list } [ assignment-expression ]
and so on.
The problem appears to be specific to array abstract declarators used in
this manner, sizeof expressions with more ridiculous type names such as:
sizeof (struct { int a; } (*[2])(struct { int a; }))
appear to work just fine in clang. With clang, the program is rejected
with this pile of error messages:
% clang -O -std=c11 -Wall -pedantic test.c
test.c:5:46: error: expected ';' after struct
printf("%zu\n", sizeof (struct { int a; } [2]));
^
;
test.c:5:47: error: expected ')'
printf("%zu\n", sizeof (struct { int a; } [2]));
^
test.c:5:28: note: to match this '('
printf("%zu\n", sizeof (struct { int a; } [2]));
^
test.c:5:47: error: expected ')'
printf("%zu\n", sizeof (struct { int a; } [2]));
^
test.c:5:11: note: to match this '('
printf("%zu\n", sizeof (struct { int a; } [2]));
^
test.c:5:47: error: expected expression
printf("%zu\n", sizeof (struct { int a; } [2]));
^
4 errors generated.
None of the error messages are helpful. GCC accepts the program and
works correctly.
--
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20140812/c43558a0/attachment.html>
More information about the llvm-bugs
mailing list