[clang] [clang] Compound Literal Statement Constant Expression Assertion Fix (PR #139479)
via cfe-commits
cfe-commits at lists.llvm.org
Sun May 11 23:37:43 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())
----------------
cor3ntin wrote:
This is not checking for "outside of the function".
Note that GCC errors on these cases too https://compiler-explorer.com/z/TaqzEdnbe
I think you need to update the comment to better describe the check
https://github.com/llvm/llvm-project/pull/139479
More information about the cfe-commits
mailing list