CWG2403 deals with the issue that copy elision is not possible when the
initialized object is a potentially-overlapping subobject and the
initializer is a function that returns by value. Jonathan pointed out that
this also affects delegating constructors, which might be used to construct
a base subobject.
gcc/cp/ChangeLog:
* call.cc (unsafe_return_slot_p): Return 2 for *this in a
constructor.
gcc/testsuite/ChangeLog:
* g++.dg/init/elide8.C: New test.
if (is_empty_base_ref (t))
return 2;
+ /* A delegating constructor might be used to initialize a base. */
+ if (current_function_decl
+ && DECL_CONSTRUCTOR_P (current_function_decl)
+ && (t == current_class_ref
+ || tree_strip_nop_conversions (t) == current_class_ptr))
+ return 2;
+
STRIP_NOPS (t);
if (TREE_CODE (t) == ADDR_EXPR)
t = TREE_OPERAND (t, 0);
--- /dev/null
+// CWG 2403 case 3: we can't elide this copy because the delegating constructor
+// might be used to initialize a base.
+// { dg-do compile { target c++11 } }
+
+struct Noncopyable {
+ Noncopyable() = default;
+ Noncopyable(const Noncopyable &) = delete;
+ Noncopyable(int) : Noncopyable(make()) {} // { dg-error "deleted" }
+
+ static Noncopyable make();
+};