[clang] [clang] Compound Literal Statement Constant Expression Assertion Fix (PR #139479)
Mariya Podchishchaeva via cfe-commits
cfe-commits at lists.llvm.org
Mon May 12 01:41:33 PDT 2025
================
@@ -7220,6 +7220,17 @@ Sema::BuildCompoundLiteralExpr(SourceLocation LParenLoc, TypeSourceInfo *TInfo,
if (auto ILE = dyn_cast<InitListExpr>(LiteralExpr))
for (unsigned i = 0, j = ILE->getNumInits(); i != j; i++) {
Expr *Init = ILE->getInit(i);
+ // C99 6.5.2.5
+ // "If the compound literal occurs outside the body of a function, the
+ // initializer list shall consist of constant expressions."
+ if (!Init->isTypeDependent() && !Init->isValueDependent() &&
+ !Init->getType()->isDependentType())
+ if (!Init->isConstantInitializer(Context, false)) {
----------------
Fznamznon wrote:
A code style nit, we try to add comments explaining the values with parameter name
```suggestion
if (!Init->isConstantInitializer(Context, /*IsForRef=*/ false)) {
```
https://github.com/llvm/llvm-project/pull/139479
More information about the cfe-commits
mailing list