<html>
<head>
<base href="https://bugs.llvm.org/">
</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 allows static VLAs for C99"
href="https://bugs.llvm.org/show_bug.cgi?id=40602">40602</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>clang allows static VLAs for C99
</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>enhancement
</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>henric.karlsson@ericsson.com
</td>
</tr>
<tr>
<th>CC</th>
<td>htmldeveloper@gmail.com, llvm-bugs@lists.llvm.org, neeilans@live.com, richard-llvm@metafoo.co.uk
</td>
</tr></table>
<p>
<div>
<pre>Created <span class=""><a href="attachment.cgi?id=21434" name="attach_21434" title="example code">attachment 21434</a> <a href="attachment.cgi?id=21434&action=edit" title="example code">[details]</a></span>
example code
It seems like clang is at least not consistent with how VLAs are allowed, and I
think clang is a bit too permissive. A VLA should not be allowed as static
variable.
reproducer command:
clang -S -std=c99 vla_tst.c
Code below is the same as in attached file vla_tst.c
Consider the following:
const int xx = 1;
- gcc gives an error for arrx, and global VLAs sounds strange, but clang
accepts this, possibly because xx is known at compiletime? But is not a
"constant expression" so should still be a VLA.
int arrx[xx];
- here clang gives an error for arr2 but not arr1. gcc gives an error for the
garr typedef (and arr2).
typedef int garr[xx];
void fn0() {
typedef int larr[xx];
static garr arr1;
static larr arr2;
}
- clang accepts arr3, but a static storage should not be allowed for a VLA.
void fn1() {
const int a = 1;
static int arr3[a];
}
- Here arr4 correctly results in an error with clang. So a little confusing why
clang allows some cases but not all.
void fn2() {
const int a = 1;
typedef int at[a];
static at arr4;
}
With -Wpedantic you get warnings for these (from C++ extension? )</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>