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 & on temporary
- From: "bangerth at dealii dot org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 14 May 2007 16:50:44 -0000
- Subject: [Bug c++/986] g++ misses warning for & on temporary
- References: <bug-986-184@http.gcc.gnu.org/bugzilla/>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
------- Comment #21 from bangerth at dealii dot org 2007-05-14 17:50 -------
This is getting completely off-topic, so here's my last post:
(In reply to comment #20)
> Can someone provide a program with that undefined behaviour that could not be
> considered an error?
As long as you don't touch the undefined value, everything's ok:
-----------------
struct X { X (int); };
struct Y {
Y ();
int do_something () { return 1; }
const X &x; // note the ampersand
};
Y::Y () : x(1) {}; // creates a temporary and stores address
int main () {
Y y;
return y.do_something();
}
----------------------
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=986