public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/49974] New: missing warning for indirectly returning reference to local/temporary
@ 2011-08-04 12:23 redi at gcc dot gnu.org
  2011-08-04 12:29 ` [Bug c++/49974] " manu at gcc dot gnu.org
                   ` (9 more replies)
  0 siblings, 10 replies; 11+ messages in thread
From: redi at gcc dot gnu.org @ 2011-08-04 12:23 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49974

           Summary: missing warning for indirectly returning reference to
                    local/temporary
           Product: gcc
           Version: 4.7.0
            Status: UNCONFIRMED
          Keywords: diagnostic
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: redi@gcc.gnu.org


Although probably not easy, it would be useful to get warnings from this code
which creates dangling references:

struct X { };

inline const X& f(const X& r) { return r; }

const X& g()
{
    X x;
    return f(x);  // !!!
}

const X& h()
{
    return f(X()); // !!!
}

Another case involves a reference as a member of a class:

struct Y {
    Y(int& i) : r(i) { }
    int& r;
};

Y f()
{
    int i=0;
    return Y(i);
}


^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2024-02-15 18:44 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-08-04 12:23 [Bug c++/49974] New: missing warning for indirectly returning reference to local/temporary redi at gcc dot gnu.org
2011-08-04 12:29 ` [Bug c++/49974] " manu at gcc dot gnu.org
2011-08-04 12:40 ` redi at gcc dot gnu.org
2011-08-04 12:49 ` rguenth at gcc dot gnu.org
2012-04-08 18:15 ` redi at gcc dot gnu.org
2013-06-05 18:26 ` paolo.carlini at oracle dot com
2020-06-26 13:48 ` [Bug c++/49974] missing -Wreturn-local-addr " redi at gcc dot gnu.org
2020-06-26 13:54 ` redi at gcc dot gnu.org
2022-01-16  0:37 ` msebor at gcc dot gnu.org
2024-02-15 18:39 ` barry.revzin at gmail dot com
2024-02-15 18:44 ` pinskia at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).