mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 22:02:55 +01:00
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:
@@ -267,9 +267,12 @@ auto EvalCppCall(Context& context, SemIR::LocId loc_id,
|
||||
clang::Expr::EvalResult eval_result;
|
||||
eval_result.Diag = ¬es;
|
||||
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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user