From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id B66B8395C027; Thu, 14 May 2020 11:59:02 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B66B8395C027 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1589457542; bh=u6fqe4ws8pfSRMn/ZTLdU1UEAjtZKa6iUd9M0dUmmNM=; h=From:To:Subject:Date:In-Reply-To:References:From; b=R9PAkuc6GF+lM2i7Q177hIesX7LHDcZTdJjy4WfDLq2FkINYdydIVJlnRz0d11bi1 2biOcLnFW+Bzv2EQjf7dG8V6oSDZd0IucHmS3auGXPE04GTGK3iWiQeL0SmPtAI9pK WLxr7bfNQpZJ95pdX0nsH9BHyCFd3iGF9yi7xUHc= From: "ville.voutilainen at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/95111] coroutines use-after-free with lambdas Date: Thu, 14 May 2020 11:59:01 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: 10.1.1 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: ville.voutilainen at gmail dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: iains at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 14 May 2020 11:59:02 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D95111 --- Comment #17 from Ville Voutilainen = --- (In reply to Ville Voutilainen from comment #16) > (In reply to Iain Sandoe from comment #14) > > (In reply to Ville Voutilainen from comment #12) > > The idea of bringing the lambda's captures into the coro frame was what= I > > originally implemented. Richard pointed out that this is wrong when the > > lambda is mutable (see > > gcc/testsuite/g++.dg/coroutines/torture/lambda-10-mutable.C) > >=20 > > so if one has > >=20 > > auto X =3D [...] () -> some_coro {}; > >=20 > > X must exist for the duration of the lambda coro [it was pointed out by > > Lewis that really this is only the same as saying that if you have a cl= ass > > with a member function lambda, the instance of that class has to persis= t for > > the duration of the coro]. >=20 > Ah. So the work-around for this problem is to copy the capture to a local > variable, and co_return that; then the local variable is in the coro-stat= e. > Right? That is, instead of writing [x] {co_return x;} write [x] {auto xx =3D x; co_return xx;}=