[PATCH] D16465: [MS ABI] Prevent some expressions from evaluating to a constant

Reid Kleckner via cfe-commits cfe-commits at lists.llvm.org
Fri Feb 26 15:22:26 PST 2016

rnk added a comment.

Richard really is the constexpr owner so I'd like him to chime in if he can.

Comment at: include/clang/AST/Decl.h:1092
@@ -1091,3 +1091,3 @@
   /// succeeded, 0 otherwise.
-  APValue *evaluateValue() const;
-  APValue *evaluateValue(SmallVectorImpl<PartialDiagnosticAt> &Notes) const;
+  APValue *evaluateValue(bool RespectMicrosoftABIIfNeeded = false) const;
+  APValue *evaluateValue(SmallVectorImpl<PartialDiagnosticAt> &Notes,
Maybe this parameter would be better named `IsStaticLocalInit` or something.

Comment at: include/clang/Basic/DiagnosticASTKinds.td:151
@@ -150,1 +150,3 @@
+def note_constexpr_microsoft_abi_declrefexpr : Note<
+  "in the Microsoft ABI static local variables cannot contain references to "
> One solution to this would be to create a variation of evaluateValue() which activates this new behavior and only use it from CodeGenModule::EmitConstantInit(), so that the behavior of evaluateValue() in this context doesn't change. How does that sound?

Right, only having this behavior change in the awkward static local case is good.

> By the way, I just realized that CheckPotentialExpressionContainingDeclRefExpr() eats this diagnostic because of the SpeculativeLookForDeclRefExprRAII object. Should I propagate it up from CheckPotentialExpressionContainingDeclRefExpr() to make it user visible? Right now the test case above only emits "constexpr variable 'p' must be initialized by a constant expression" without any notes.

Yeah, I'd like it if we could get that note out. I'm surprised we can't use the normal recursive traversal to find the DeclRefExprs...


More information about the cfe-commits mailing list