[clang] [Clang] Treat constexpr-unknown value as invalid in `EvaluateAsInitializer` (PR #128409)
Yingwei Zheng via cfe-commits
cfe-commits at lists.llvm.org
Wed Feb 26 21:22:21 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:
> If you need more information to generate a good diagnostic, you could pass that information to createConstexprUnknownAPValues, and store it in the APValue itself, I guess. Computing the whole diagnostic in advance seems like it would be too expensive, though.
That is what the current implementation does.
https://github.com/llvm/llvm-project/pull/128409
More information about the cfe-commits
mailing list