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++/57610] Reference initialized with temporary instead of sub-object of conversion result


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

--- Comment #7 from Ole Kniemeyer <o_kniemeyer at maxon dot net> ---
OK, thanks for your comments. I wasn't aware of the ongoing discussion about
this issue (I was referring to the the draft version N3376 of the C++11
standard).

A B-copy would be OK, but as I said copying B into A is not a good idea if
those classes have virtual functions. The N3376 wording would be much better
for such cases.

In my case A is an interface (with dummy implementations of the virtual
functions), B an implementation of A and X an unrelated class with conversion
operator to B. Now if a function has a const A& parameter (so it works with the
interface), N3376 allows me to pass an X object to this function by implicitly
creating a temporary B object which makes X look like an A. With the variant
discussed in the links you posted this wouldn't work (copying B into A makes no
sense).


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