From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 6133F3858C66; Sun, 3 Mar 2024 10:30:26 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6133F3858C66 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1709461826; bh=Rgv5aj9t/HSzTdklM1SAD+NuNGZVW0GB0dDupRMC8jA=; h=From:To:Subject:Date:In-Reply-To:References:From; b=QWZ0tO2zJKdXXWksFPVdZrtbp0RSfD5S2xxix1SteQ1YWfskyrFsfMZ3HVZfC68PR WPu/o+tzhe4iY0/YLoDewzls4VsNAUyqPZK/fW86N28j0CTm/E5ZeMZl6bTlvWYhP3 VHZh/04SO3DMumbfUSAxQvWbvqNSFX0SJbf8i/Bs= From: "dilyan.palauzov at aegee dot org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/114220] False positive warning: possibly dangling reference to a temporary [-Wdangling-reference] Date: Sun, 03 Mar 2024 10:30:26 +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.2.1 X-Bugzilla-Keywords: diagnostic X-Bugzilla-Severity: normal X-Bugzilla-Who: dilyan.palauzov at aegee dot org X-Bugzilla-Status: RESOLVED X-Bugzilla-Resolution: INVALID 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: 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=3D114220 --- Comment #3 from =D0=94=D0=B8=D0=BB=D1=8F=D0=BD =D0=9F=D0=B0=D0=BB=D0=B0= =D1=83=D0=B7=D0=BE=D0=B2 --- > The warning is designed this way explictly because you are returning a re= ference and taking a reference as an argument and in the case of b2, the te= mpory is `std::string("u")` . > In GCC 14+ (since r14-9263-gc7607c4cf18986), you can add [[gnu::no_dangli= ng]] to the z2 function definition to mark it as not returning a dangling r= eference (from the arguments). and the warning goes away. If the declaration and definitions are in different files, do I have to add [[gnu::no_dangling]] only to the function declaration ? That said, is the warning triggered only based on the function declaration (accepting as parameter a reference to temporary and returning a reference), when on the function invocation the parameter is indeed a reference to a temporary?=