[clang] [Clang] Treat constexpr-unknown value as invalid in `evaluateValue` (PR #128409)
Yingwei Zheng via cfe-commits
cfe-commits at lists.llvm.org
Wed Feb 26 08:12:01 PST 2025
================
@@ -17000,6 +16998,18 @@ bool Expr::EvaluateAsInitializer(APValue &Value, const ASTContext &Ctx,
if (!Info.discardCleanups())
llvm_unreachable("Unhandled cleanup; missing full expression marker?");
+
+ if (Value.allowConstexprUnknown()) {
+ assert(Value.isLValue() && "Expected an lvalue");
+ auto Base = Value.getLValueBase();
+ const auto *NewVD = Base.dyn_cast<const ValueDecl *>();
+ if (!NewVD)
+ NewVD = VD;
+ Info.FFDiag(getExprLoc(), diag::note_constexpr_var_init_non_constant, 1)
----------------
dtcxzyw wrote:
Ideally, we should emit a note here:
https://github.com/llvm/llvm-project/blob/a955426a16bcbb9bf05eb0e3894663dff4983b00/clang/lib/AST/ExprConstant.cpp#L3581-L3584
But I don't know how to add a "lazy" note (i.e., these notes will be shown if an error occurs).
https://github.com/llvm/llvm-project/pull/128409
More information about the cfe-commits
mailing list