<html>
<head>
<base href="http://llvm.org/bugs/" />
</head>
<body><table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Bug ID</th>
<td><a class="bz_bug_link
bz_status_NEW "
title="NEW --- - clang incorrectly parses array declarators in sizeof operand."
href="http://llvm.org/bugs/show_bug.cgi?id=20634">20634</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>clang incorrectly parses array declarators in sizeof operand.
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>trunk
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>Linux
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>normal
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>-New Bugs
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>nbowler@draconx.ca
</td>
</tr>
<tr>
<th>CC</th>
<td>llvmbugs@cs.uiuc.edu
</td>
</tr>
<tr>
<th>Classification</th>
<td>Unclassified
</td>
</tr></table>
<p>
<div>
<pre>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.</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are on the CC list for the bug.</li>
</ul>
</body>
</html>