================
@@ -7541,18 +7541,57 @@ 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, apart from a
+        // string literal initializing an array.
+        bool IsRef = Init->isGLValue() &&
+                     !isa<StringLiteral, ObjCEncodeExpr>(Init->IgnoreParens());
----------------
akash-manna-sky wrote:

You're right, I had that backwards. An `-ast-dump` shows the string literal 
elements of `(const char[4]){"abc"}` and `(const char[2][4]){"abc", "def"}` as 
prvalues; `updateStringLiteralType` in SemaInit marks a string literal 
initializing an array as `VK_PRValue`, so the exclusion was dead code. It's 
just `Init->isGLValue()` now. Sorry for the noise.


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