[Bug c++/986] g++ misses warning for & on temporary

bangerth at dealii dot org gcc-bugzilla@gcc.gnu.org
Mon May 14 16:50:00 GMT 2007



------- 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



More information about the Gcc-bugs mailing list