This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/986] g++ misses warning for reference on temporary that invokes undefined behaviour


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

--- Comment #31 from Jonathan Wakely <redi at gcc dot gnu.org> 2011-08-04 13:01:31 UTC ---
A similar case I've just added to a comment of PR 49974

struct Y {
    Y(int local) : ref(local) { }
    int& ref;
};

The reference is dangling as soon as the constructor exits, but in this case
it's bound to a block-scope function parameter with automatic storage duration,
not to a temporary.

I would imagine this could be caught in perform_member_init() by checking if
the member has reference type, then if the initializer has the same type but
DECL_FUNCTION_SCOPE_P is true warn about binding to a local.  But I haven't
tried to do that.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]