<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/118331>118331</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[Clang 19.1.4] [C23] VLA warning / usage when size is specified as member of static constexpr struct
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
florianmarkusse
</td>
</tr>
</table>
<pre>
Hi there,
I recently upgraded my personal project to the new C23 standard when I saw that Clang 19.1.4 supports both `constexpr` and `#embed`. Both features have helped my project get rid of some manual things, thanks for that.
However, when I create a `static constexpr struct` and use its member to set the size of an array, Clang warns me about VLA usage. These come in 2 flavors. See this [godbolt](https://godbolt.org/z/jE3ecr5en).
- Warning about `VLA` usage which is then folded into a constant array as an extension.
- Waqning about `VLA` usage
I will post the code here again:
```C
static constexpr struct
{ int SHIFT;
int ENTRIES;
}
PageTableFormat = {.SHIFT = 9, .ENTRIES = (1ULL << PageTableFormat.SHIFT)}; // Emits '-Wgnu-folding-constant'
static int arraysOfThings[(enum {SIZE = PageTableFormat.ENTRIES})SIZE];
int testFunction() {
int canIBeConstant[SIZE];
return 3;
}
static constexpr int size = PageTableFormat.ENTRIES;
int testFunction2() {
int canIBeConstant[size];
return 3;
}
int testFunction3() {
int canIBeConstant[PageTableFormat.ENTRIES]; // Emits '-Wvla'
return 3;
}
static int new_arraysOfThings[PageTableFormat.ENTRIES]; // Emits ' -Wvla' and '-Wgnu-folding-constant'
// Using a constexpr like this does work as expected
static constexpr int THIS_DOES_WORK_SIZE = 10;
int testFunction4() {
int iAmConstant[THIS_DOES_WORK_SIZE];
return 3;
}
int constantArray[THIS_DOES_WORK_SIZE];
```
**Expected behavior**
- Clang compiles by turning the arrays into constant arrays and not VLAs.
- Clang does not emit a warning about using a VLA `[-Wvla]` if the array is folded into a constant array [`-Wgnu-folding-constant`]
- NOTE: Should Clang even emit the [`-Wgnu-folding-constant`] warning? According to [N3220](https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3220.pdf) paragraph 5.6:
> An identifier that is ... declared with storage-class specifier constexpr and has an object type, is a named constant, as is a postfix expression that applies the . member access operator to a named constant of structure or union type, even recursively.
So, i think that even [`-Wgnu-folding-constant`] shouldn't be emitted since it is part of the standard, right?
**Affected version**
`Clang 19.1.0` and up
**How to Reproduce**
- Use `Clang 19.1.0` or newer
- Create a `static constexpr struct` and use the member variable as the size of an array in a function or as an array inside a translation unit. and compile
When creating a standalone `static constexpr auto` variable, Clang behaves as expected: No `VLA` is used and no warning for folding a constant is emitted.
Please let me know if you require more information. This is my first issue, I hope it is clear :)
Thanks for providing and maintaining this amazing tool!
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyUV01v27oS_TXMZhBBovy58MJObCR4RXvRuLfA2xRjaSyxkUhdkrKb_vqHIeXYNy9pU8BAG4mcOfN15gidU5UmWojxSoxvr7D3tbGLfWOsQt2ifeydo6udKZ8Wdwp8TZaEvBHpMv7uwVJB2jdP0HeVxZJKaJ-gI-uMxgY6a75T4cEbvguajnAjc3AedYm2hGNNGu7B4RF8jR5uGtQVZPMkS0bg-q4z1jvYGV-DmKSF0c7Tj86KSQqoS34mZE7tjkoxSRNY8cE9oe8tOajxQFBT0w2gBiwVebCqBLMHZ1qCFnWPDfha6coJecNI9KODvbEBVBJDvTNHOpDlAwPqwhJ6AmQYzqNXBTwjBOdtX_gT0N4RKO-gZayW0-HIh5Q49ZMYCmpAa_GJ7ccsHNFqvgG4M72Hvz8soXdYUQLbmhxBweCVBgn7Bg_GugQeiDgOB2K8qky5M40X41shZ7X3nRP5UsiNkJvhVWJsJeTmp5Cb7-ucCjsmLeQ8AZEur-ErWq10NXgXk_TvD0sOJ2CAY62KGpTjGDTsTcOVV9obwJgE1D4GBOg4OPrhSTtl9LP5f35h_tRdR9U00BkXc1WYkgtqCbBCpTmelC_FH3flW2VIl2K6AmCE8HB3v9mKfCXSJQy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