From: Jason Merrill Date: Fri, 26 Jul 2024 20:53:03 +0000 (-0400) Subject: c++: ICE with concept, local class, and lambda [PR115561] X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=b300fd3985cc1435ecea30d18d00bfab8022d091;p=thirdparty%2Fgcc.git c++: ICE with concept, local class, and lambda [PR115561] Here when we want to synthesize methods for foo()::B maybe_push_to_top_level calls push_function_context, which sets cfun to a dummy value; later finish_call_expr tries to set something in cp_function_chain (i.e. cfun->language), which isn't set. Many places in the compiler check cfun && cp_function_chain to avoid this problem; here we also want to check !cp_unevaluated_operand, like set_flags_from_callee does. PR c++/115561 gcc/cp/ChangeLog: * semantics.cc (finish_call_expr): Check cp_unevaluated_operand. gcc/testsuite/ChangeLog: * g++.dg/cpp2a/concepts-lambda21.C: New test. --- diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index 0f122b839c5f..a9abf32e01ff 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -2968,7 +2968,7 @@ finish_call_expr (tree fn, vec **args, bool disallow_virtual, -Wredundant-move warning. */ suppress_warning (result, OPT_Wpessimizing_move); - if (cfun) + if (cfun && cp_function_chain && !cp_unevaluated_operand) { bool abnormal = true; for (lkp_iterator iter (maybe_get_fns (fn)); iter; ++iter) diff --git a/gcc/testsuite/g++.dg/cpp2a/concepts-lambda21.C b/gcc/testsuite/g++.dg/cpp2a/concepts-lambda21.C new file mode 100644 index 000000000000..8d701cd4bbc4 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp2a/concepts-lambda21.C @@ -0,0 +1,69 @@ +// PR c++/115561 +// { dg-do compile { target c++20 } } + +template +auto declval() noexcept -> _Tp&&; + +template +struct enable_if +{ }; + +template +struct enable_if +{ using type = _Tp; }; + +template +using enable_if_t = typename enable_if<_Cond, _Tp>::type; + +template +struct is_void +{ static constexpr bool value = false; }; + +template +using invoke_result_t = + decltype(declval()(declval()...)); + +template +using iter_reference_t = decltype(*declval()); + +struct iter_move_fn +{ + template + constexpr + auto operator() (I &&i) -> void; +} iter_move; + +template +using iter_rvalue_reference_t = decltype(iter_move(declval())); + +template +concept same_as = true; + +template +concept readable_concept_ = + same_as, iter_rvalue_reference_t>; + +template +concept indirectly_readable = + readable_concept_>; + +template +using indirect_result_t = + enable_if_t, + invoke_result_t>>; + +template +concept transformable = + (!is_void>::value); + +template + requires transformable +constexpr void transform(I, Fun) +{ +} + +void foo() +{ + struct B {}; + (void) transform((B*)nullptr, [](B) {return 0; }); +}