Allow non-constant calls to constexpr functions. (#7067)

These turn up frequently in real-world code, for example when converting
a mutable global `Cpp.std.string_view` to a `Cpp.std.string`. Only
reject a non-constant call if the callee is `consteval`, not if it's
`constexpr`.
This commit is contained in:
Richard Smith
2026-04-16 17:10:48 +00:00
committed by GitHub
parent cdfa57f230
commit 1d5113649b
2 changed files with 58 additions and 10 deletions
+4 -1
View File
@@ -267,9 +267,12 @@ auto EvalCppCall(Context& context, SemIR::LocId loc_id,
clang::Expr::EvalResult eval_result;
eval_result.Diag = &notes;
if (!call_expr->EvaluateAsConstantExpr(eval_result, context.ast_context())) {
if (!function_decl->isConsteval()) {
return SemIR::ConstantId::NotConstant;
}
context.clang_sema().Diag(call_expr->getBeginLoc(),
clang::diag::err_invalid_consteval_call)
<< function_decl << function_decl->isConsteval();
<< function_decl << /*is consteval*/ true;
for (const auto& note : notes) {
context.clang_sema().Diag(note.first, note.second);
}