================
@@ -7541,18 +7541,53 @@ Sema::BuildCompoundLiteralExpr(SourceLocation 
LParenLoc, TypeSourceInfo *TInfo,
   //  "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))
+    if (auto ILE = dyn_cast<InitListExpr>(LiteralExpr)) {
+      // A default argument or default member initializer containing an
+      // immediate call or source_location is rebuilt at each use site, where
+      // its elements are evaluated (see BuildCXXDefaultArgExpr).
+      bool InDefaultArgOrInit =
+          isCheckingDefaultArgumentOrInitializer() ||
+          InnermostDeclarationWithDelayedImmediateInvocations().has_value();
       for (unsigned i = 0, j = ILE->getNumInits(); i != j; i++) {
         Expr *Init = ILE->getInit(i);
-        if (!Init->isTypeDependent() && !Init->isValueDependent() &&
-            !Init->isConstantInitializer(Context)) {
+        // An immediate invocation is already a ConstantExpr and receives its
+        // value at the end of the full-expression.
+        if (isa<ConstantExpr>(Init))
+          continue;
+        if (Init->isTypeDependent() || Init->isValueDependent()) {
+          ILE->setInit(i, ConstantExpr::Create(Context, Init));
+          continue;
+        }
+        // Only a reference member is initialized by a glvalue. Like other
+        // constant initializers, undefined behavior such as signed overflow
+        // is folded with a warning.
+        Expr::EvalResult Eval;
+        bool Evaluated =
+            Init->isGLValue()
+                ? Init->EvaluateAsLValue(Eval, Context,
+                                         /*InConstantContext=*/true)
+                : Init->EvaluateAsRValue(Eval, Context,
+                                         /*InConstantContext=*/true);
----------------
tbaederr wrote:

But `EvaluateAsRValue` only does the lvalue-to-rvalue conversion if 
`(E->isGLValue()`. Do we need this conditional operator at all?

https://github.com/llvm/llvm-project/pull/221390
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to