[clang] [clang] Compound Literal Statement Constant Expression Assertion Fix (PR #139479)

via cfe-commits cfe-commits at lists.llvm.org
Mon May 12 05:21:28 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)) {
----------------
Mr-Anyone wrote:

done, thanks. 

https://github.com/llvm/llvm-project/pull/139479


More information about the cfe-commits mailing list