[Bug c++/17435] Temporay bound to reference is immediately destructed
bangerth at dealii dot org
gcc-bugzilla@gcc.gnu.org
Sun Sep 12 23:22:00 GMT 2004
------- Additional Comments From bangerth at dealii dot org 2004-09-12 23:21 -------
This example makes it slightly clearer what happens:
------------------
#include <iostream>
#include <typeinfo>
struct A {
virtual ~A() {};
};
struct B : public A { };
int main() {
A const& r1 = B();
std::cout << typeid(r1).name() << std::endl;
}
------------------------
g/x> /home/bangerth/bin/gcc-3.5-pre/bin/c++ x.cc
g/x> ./a.out
1A
g/x> /home/bangerth/bin/gcc-3.3.4-pre/bin/c++ x.cc
g/x> ./a.out
1B
g/x> icc -Xc -ansi -c x.cc
g/x> ./a.out
1B
In contrast to older versions of gcc and to icc, gcc chooses to copy the
A part of the object created by B() when it assigns to the reference.
I believe that this is standard conforming, and that gcc is allowed (though
not required) to do so, but someone else will have to look up the respective
sentence of the standard.
W.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17435
More information about the Gcc-bugs
mailing list