From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 30499 invoked by alias); 4 Aug 2011 12:40:53 -0000 Received: (qmail 30489 invoked by uid 22791); 4 Aug 2011 12:40:53 -0000 X-SWARE-Spam-Status: No, hits=-2.9 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00 X-Spam-Check-By: sourceware.org Received: from localhost (HELO gcc.gnu.org) (127.0.0.1) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 04 Aug 2011 12:40:39 +0000 From: "redi at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/49974] missing warning for indirectly returning reference to local/temporary X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Keywords: diagnostic X-Bugzilla-Severity: enhancement X-Bugzilla-Who: redi at gcc dot gnu.org X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Changed-Fields: Severity Message-ID: In-Reply-To: References: X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated Content-Type: text/plain; charset="UTF-8" MIME-Version: 1.0 Date: Thu, 04 Aug 2011 12:40:00 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2011-08/txt/msg00510.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49974 Jonathan Wakely changed: What |Removed |Added ---------------------------------------------------------------------------- Severity|normal |enhancement --- Comment #2 from Jonathan Wakely 2011-08-04 12:40:15 UTC --- Maybe related, but not the same. PR986 involves creating a temporary and binding the reference to it, that should be easier to warn about. Here's a similar case to PR986 where a reference member is dangling after the constructor, which we fail to warn about: struct Y { Y(int local) : ref(local) { } int& ref; }; That, and the example in 986, should be easy to warn about. When the reference is bound we can know if the initializer is local/temporary. This PR is different, the references passed to f and Y::Y are valid during those calls. The reference only becomes invalid when it escapes from the function that declares the local variable. This requires some more complex analysis, only possible if the bodies of f and Y::Y are visible, and maybe only possible with optimization enabled so inlining happens.