================
@@ -5223,10 +5223,31 @@ class Parser : public CodeCompletionHandler {
   ///         assignment-expression
   ///         '{' ...
   /// \endverbatim
-  ExprResult ParseInitializer() {
-    if (Tok.isNot(tok::l_brace))
-      return ParseAssignmentExpression();
-    return ParseBraceInitializer();
+  ExprResult ParseInitializer(Decl *DeclForInitializer = nullptr) {
+    // Set DeclForInitializer for file-scope variables.
+    // For constexpr references, set it to suppress runtime warnings.
+    // For non-constexpr references, don't set it to avoid evaluation issues
+    // with self-referencing initializers. Local variables (including local
+    // constexpr) should emit runtime warnings.
+    if (DeclForInitializer && !Actions.ExprEvalContexts.empty()) {
+      if (auto *VD = dyn_cast<VarDecl>(DeclForInitializer)) {
+        if (VD->isFileVarDecl()) {
+          if (!VD->getType()->isReferenceType() || VD->isConstexpr()) {
+            Actions.ExprEvalContexts.back().DeclForInitializer =
+                DeclForInitializer;
+          }
+        }
+      }
+    }
+
+    ExprResult init;
+    if (Tok.isNot(tok::l_brace)) {
+      init = ParseAssignmentExpression();
+    } else {
+      init = ParseBraceInitializer();
+    }
+
+    return init;
   }
----------------
zwuis wrote:

Do we need to move the implementation to source file(.cpp)?

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

Reply via email to