From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id EA45C3858C62; Sat, 24 Jun 2023 16:15:58 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org EA45C3858C62 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1687623358; bh=Is29L0aSO6j3qB02Pk7tWXDqjiMogw9mM6hhM6WSRzU=; h=From:To:Subject:Date:In-Reply-To:References:From; b=MuN2wxBTEOBXAg0LmGHOb3o1QemT4CB6qagQrvUEMgUDRkC+mr7cWivDtJJsI7L7C wK1GcED5zb0ZTRLeBqMEbaw04iOsvLYCJ7SnlDJFEAVk2AiZ639ltOhO+w4/uafdmC wvqFy9NRFuL46xbF0UpGhJttv1Egc6yhOGGLXYZw= From: "pinskia at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/110394] Lambda capture receives wrong value Date: Sat, 24 Jun 2023 16:15:58 +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: 13.1.1 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: pinskia at gcc dot gnu.org X-Bugzilla-Status: WAITING X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_status cf_reconfirmed_on everconfirmed 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 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D110394 Andrew Pinski changed: What |Removed |Added ---------------------------------------------------------------------------- Status|UNCONFIRMED |WAITING Last reconfirmed| |2023-06-24 Ever confirmed|0 |1 --- Comment #2 from Andrew Pinski --- I am almost think this is a bug in your code. Take: auto wait_handle =3D tc::g_postbox->wait( "UpdateInputs"sv, [=3D](const msgpack::object& obj) -> bool { .... }); The temporary for tc::postbox::acceptor_type will end its lifetime at the e= nd of that statement but tc::g_postbox->wait stores it off into m_awaiters. And then gets poped off with: wait_handle.await(); You can fix this via extending the temporary via: ``` tc::postbox::acceptor_type t =3D [=3D](const msgpack::object& obj) -> boo= l { auto [rcv_index, rcv_value] =3D obj.as>(); tc::tracef(M64MSG_VERBOSE, "index =3D {}", index); if (rcv_index !=3D index) return false; keys->Value =3D rcv_value; return true; }; auto wait_handle =3D tc::g_postbox->wait( "UpdateInputs"sv, t); ``` Note `-fsantize=3Daddress` should catch this at runtime too.=