From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 557863857C66; Sat, 28 Oct 2023 21:26:47 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 557863857C66 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1698528407; bh=7HFrwrVBSVVuuTimRFmILcYqPPzXrPitp665G3FWvfc=; h=From:To:Subject:Date:In-Reply-To:References:From; b=wCiGKRXieCspdUpXr/N910a1tb/200zln1zWkQUZ/xVHThVMMY1RSV8gF1dC+wcVT 420gbMALy86cYMdpnBES0z0wjuzhQ1m8cVC9hRqE+e84XD4nf48PEXxdofr57gojkH w4C5NRTI4WL0MBiNMzeK+WXeAxZSdfeTOwd7BW+Y= From: "roystgnr at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/110075] Bogus -Wdangling-reference Date: Sat, 28 Oct 2023 21:26:46 +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: diagnostic X-Bugzilla-Severity: normal X-Bugzilla-Who: roystgnr at gmail dot com X-Bugzilla-Status: UNCONFIRMED 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: 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 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D110075 Roy Stogner changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |roystgnr at gmail dot com --- Comment #2 from Roy Stogner --- This case looks most similar to the one that my code triggered, which I simplified to the following: --- #include const double & find_wrapper(const std::map & map, const int & key) { auto it =3D map.find(key); return it->second; } int main(void) { std::map testmap{{1,0.0}}; const double & d =3D find_wrapper(testmap, 1); return int(d); } --- $ g++ -Wall -Wextra -Werror -o test.x test.C test.C: In function =E2=80=98int main()=E2=80=99: test.C:15:18: error: possibly dangling reference to a temporary [-Werror=3Ddangling-reference] 15 | const double & d =3D find_wrapper(testmap, 1); | ^ test.C:15:34: note: the temporary was destroyed at the end of the full expression =E2=80=98find_wrapper(testmap, 1)=E2=80=99 15 | const double & d =3D find_wrapper(testmap, 1); | ~~~~~~~~~~~~^~~~~~~~~~~~ cc1plus: all warnings being treated as errors --- If I change the parameter type to `const int key`, then the warning is not triggered. If I leave the parameter type as a reference but I pass in a non-temporary variable "one" instead of "1", then the warning is not trigge= red. Either or both of these cases might be a dup of bug 109642=