[clang] [clang] Disallow VLA type compound literals (PR #91891)
Tomasz Stanisławski via cfe-commits
cfe-commits at lists.llvm.org
Thu May 16 02:58:15 PDT 2024
================
@@ -7274,12 +7274,19 @@ Sema::BuildCompoundLiteralExpr(SourceLocation LParenLoc, TypeSourceInfo *TInfo,
// init a VLA in C++ in all cases (such as with non-trivial constructors).
// FIXME: should we allow this construct in C++ when it makes sense to do
// so?
- std::optional<unsigned> NumInits;
- if (const auto *ILE = dyn_cast<InitListExpr>(LiteralExpr))
- NumInits = ILE->getNumInits();
- if ((LangOpts.CPlusPlus || NumInits.value_or(0)) &&
- !tryToFixVariablyModifiedVarType(TInfo, literalType, LParenLoc,
- diag::err_variable_object_no_init))
+ //
+ // But: C99-C23 6.5.2.5 Compound literals constraint 1: The type name
+ // shall specify an object type or an array of unknown size, but not a
+ // variable length array type. This seems odd, as it allows int a[size] =
+ // {}; but forbids int a[size] = (int[size]){}; As this is what the
----------------
tstanisl wrote:
technically speaking `int a[size] = (int[size]){};` is disallowed in **ALL** C standards. A better example would be:
```
int * a = (int[size]){};
```
https://github.com/llvm/llvm-project/pull/91891
More information about the cfe-commits
mailing list