This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/986] g++ misses warning for reference on temporary that invokes undefined behaviour
- From: "redi at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Thu, 4 Aug 2011 13:02:51 +0000
- Subject: [Bug c++/986] g++ misses warning for reference on temporary that invokes undefined behaviour
- Auto-submitted: auto-generated
- References: <bug-986-4@http.gcc.gnu.org/bugzilla/>
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.