if (parm_i->this_ptr || parm_i->lambda_cobj)
{
/* We pass a reference to *this to the allocator lookup. */
- tree this_ref = cp_build_fold_indirect_ref (arg);
+ /* It's unsafe to use the cp_ version here since current_class_ref
+ might've gotten clobbered earlier during rewrite_param_uses. */
+ tree this_ref = build_fold_indirect_ref (arg);
vec_safe_push (args, this_ref);
}
else
if (parm.this_ptr || parm.lambda_cobj)
{
/* We pass a reference to *this to the param preview. */
- tree this_ref = cp_build_fold_indirect_ref (arg);
+ /* It's unsafe to use the cp_ version here since current_class_ref
+ might've gotten clobbered earlier during rewrite_param_uses. */
+ tree this_ref = build_fold_indirect_ref (arg);
vec_safe_push (promise_args, this_ref);
}
else if (parm.rv_ref)
--- /dev/null
+// PR c++/116327 - ICE in coroutine with parameter preview on lambda with captures
+
+#include <coroutine>
+
+struct coroutine{
+ struct promise_type{
+ promise_type(const auto &...){}
+ std::suspend_never initial_suspend(){ return {}; }
+ std::suspend_always final_suspend()noexcept{ return {}; }
+ void unhandled_exception(){}
+ coroutine get_return_object(){ return {}; }
+ void return_value(int)noexcept{}
+ };
+};
+
+int main(){
+ auto f = [a=0](auto) -> coroutine {
+ co_return 2;
+ };
+ f(0);
+ return 0;
+}