================
@@ -7241,10 +7241,20 @@ Sema::BuildCompoundLiteralExpr(SourceLocation 
LParenLoc, TypeSourceInfo *TInfo,
           ? VK_PRValue
           : VK_LValue;
 
+  // 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 (IsFileScope)
     if (auto ILE = dyn_cast<InitListExpr>(LiteralExpr))
       for (unsigned i = 0, j = ILE->getNumInits(); i != j; i++) {
         Expr *Init = ILE->getInit(i);
+        if (!Init->isTypeDependent() && !Init->isValueDependent())
+          if (!Init->isConstantInitializer(Context, /*IsForRef=*/false)) {
+            Diag(Init->getExprLoc(), diag::err_init_element_not_constant)
+                << Init->getSourceBitField();
+            return ExprError();
+          }
----------------
AaronBallman wrote:

```suggestion
        if (!Init->isTypeDependent() && !Init->isValueDependent() &&
            !Init->isConstantInitializer(Context, /*IsForRef=*/false)) {
          Diag(Init->getExprLoc(), diag::err_init_element_not_constant)
              << Init->getSourceBitField();
          return ExprError();
        }
```
Can combine these into a single `if`

https://github.com/llvm/llvm-project/pull/139479
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to