diff --git a/gcc/cp/constexpr.cc b/gcc/cp/constexpr.cc index 76a9176a8917..4820bcc84aa3 100644 --- a/gcc/cp/constexpr.cc +++ b/gcc/cp/constexpr.cc @@ -3077,6 +3077,15 @@ cxx_eval_call_expression (const constexpr_ctx *ctx, tree t, ctx->global->put_value (new_ctx.object, ctor); ctx = &new_ctx; } + /* An immediate invocation is manifestly constant evaluated including the + arguments of the call, so use mce_true even for the argument + evaluation. */ + if (DECL_IMMEDIATE_FUNCTION_P (fun)) + { + new_ctx.manifestly_const_eval = mce_true; + new_call.manifestly_const_eval = mce_true; + ctx = &new_ctx; + } /* We used to shortcut trivial constructor/op= here, but nowadays we can only get a trivial function here with -fno-elide-constructors. */ diff --git a/gcc/testsuite/g++.dg/cpp2a/consteval41.C b/gcc/testsuite/g++.dg/cpp2a/consteval41.C new file mode 100644 index 000000000000..76c4a5d2fff7 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp2a/consteval41.C @@ -0,0 +1,37 @@ +// PR c++/119150 +// { dg-do run { target c++20 } } + +consteval bool +foo (bool x) +{ + return x; +} + +constexpr bool +bar () +{ +#if __cpp_if_consteval >= 202106L + if consteval + { + return true; + } + else + { + return false; + } +#else + return __builtin_is_constant_evaluated (); +#endif +} + +int +main () +{ + bool a = false; + a = foo (bar ()); + if (!a) + __builtin_abort (); + bool b = foo (bar ()); + if (!b) + __builtin_abort (); +}