[Bug c++/57610] Reference initialized with temporary instead of sub-object of conversion result
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=57610 Paolo Carlini changed: What|Removed |Added Status|UNCONFIRMED |RESOLVED Resolution|--- |FIXED Target Milestone|--- |5.0 --- Comment #14 from Paolo Carlini --- Done.
[Bug c++/57610] Reference initialized with temporary instead of sub-object of conversion result
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=57610 --- Comment #13 from paolo at gcc dot gnu.org --- Author: paolo Date: Thu Apr 30 09:43:39 2015 New Revision: 222615 URL: https://gcc.gnu.org/viewcvs?rev=222615&root=gcc&view=rev Log: 2015-04-30 Paolo Carlini PR c++/57610 * g++.dg/init/ref22.C: New. Added: trunk/gcc/testsuite/g++.dg/init/ref22.C Modified: trunk/gcc/testsuite/ChangeLog
[Bug c++/57610] Reference initialized with temporary instead of sub-object of conversion result
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=57610 Paolo Carlini changed: What|Removed |Added CC|paolo.carlini at oracle dot com| --- Comment #12 from Paolo Carlini --- This is fixed in 5.1. I'm adding a testcase and closing the bug.
[Bug c++/57610] Reference initialized with temporary instead of sub-object of conversion result
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=57610 Paolo Carlini changed: What|Removed |Added CC||paolo.carlini at oracle dot com --- Comment #11 from Paolo Carlini --- I'm looking for somebody willing to *summarize* for me where do we stand on this. Is GCC already Ok vs the most recent resolutions and we could resolve the issue (maybe commit a testcase too)? Or ISO work is still pending and the bug should be suspended, as usual in such cases? Something else? Thanks.
[Bug c++/57610] Reference initialized with temporary instead of sub-object of conversion result
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=57610 Mitsuru Kariya changed: What|Removed |Added CC||kariya_mitsuru at hotmail dot com --- Comment #10 from Mitsuru Kariya --- Each status of the issues mentioned above is CWG 1287: DRWP CWG 1604: DR CWG 1650: NAD And, gcc HEAD (5.0.0) does not cause the slicing problem. cf. 5.0.0 http://melpon.org/wandbox/permlink/xQQq1n98s7blSz8x cf. 4.9.1 http://melpon.org/wandbox/permlink/l69tDXdptf1WVdAT Note that these are compiled with the option "-fno-elide-constructors". (Sorry, I don't know whether this issue should be "RESOLVED FIXED" or not, however.)
[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 #9 from Hubert Tong --- CWG 1604 may address the issues with performance and slicing mentioned in CWG 1287 which led to CWG 1650.
[Bug c++/57610] Reference initialized with temporary instead of sub-object of conversion result
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57610 Hubert Tong changed: What|Removed |Added CC||hstong at ca dot ibm.com --- Comment #8 from Hubert Tong --- Affects the candidate list for direct binding to a result of a conversion. struct Z { }; struct A { operator Z &&() const = delete; // GCC like this operator Z(); }; void zip() { Z &&x = A(); }
[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 --- 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).
[Bug c++/57610] Reference initialized with temporary instead of sub-object of conversion result
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57610 Daniel Krügler changed: What|Removed |Added CC||daniel.kruegler@googlemail. ||com --- Comment #6 from Daniel Krügler --- 1) Your example code is a bit misleading, because irrespective of your concerns the compiler is allowed to create one copy of B (and thus of A) when returning the B value as result of the function call. You cannot rely on that the compiler will not create at one copy and that is not related to this issue. 2) The core language was considering to change exactly this wording you mention, see http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_active.html#1287 The part related to the example was deferred and my understanding is that http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_active.html#1650 is now focusing on class prvalues during reference-binding sub-part. My suggestion is to suspend this bug until this core issue CWG 1650 has been resolved.
[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 #5 from Ole Kniemeyer --- Ops, sorry, of course I meant "... to older C++ standards."
[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 #4 from Ole Kniemeyer --- As I commented in the cpp example, the C++11 standard shows exactly this example in sections 8.5.3. So this is definitely a bug according to C++11. I think the GCC behaviour is correct according to older C++11 standards.
[Bug c++/57610] Reference initialized with temporary instead of sub-object of conversion result
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57610 Ole Kniemeyer changed: What|Removed |Added Status|RESOLVED|UNCONFIRMED Resolution|INVALID |--- --- Comment #3 from Ole Kniemeyer --- In the example X can be converted to B which is a derived class of A. When an A reference is initialized with an X object, the result of the X::operator B() should be used directly for the A reference, but GCC creates a temporary A object and initializes this by copy-construction from the conversion result. At least if the classes use virtual functions, this leads to wrong results.