From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 62F77395C83F; Thu, 14 May 2020 11:57:01 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 62F77395C83F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1589457421; bh=K7YOOXfg4J8rw3rFX2k9FV4Ghwa6aU0vhH0kqCNlbyc=; h=From:To:Subject:Date:In-Reply-To:References:From; b=agkA5+owVLrn/KKP4ktkvm6q1Xy1ozWk/ppf5WZzXq120yfWDEr/GQGP55ovnGXgJ nBhI+NoAXE2avMKadLr/zNgc5jqG9fzpp25OEl8xIHSaBnp8dW5oH84qbI1luNE0B7 EYTDCuFS0WgicXQL/MWQxLn5+GM3NLiiZ4/kCDvE= 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:57:00 +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: cc 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:57:01 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D95111 Ville Voutilainen changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |ville.voutilainen at gmail= dot com --- Comment #16 from Ville Voutilainen = --- (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 class > with a member function lambda, the instance of that class has to persist = for > the duration of the coro]. 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-state. Right?=