@@ -1579,6 +1579,7 @@ set_std_cxx1z (int iso)
flag_isoc94 = 1;
flag_isoc99 = 1;
flag_isoc11 = 1;
+ flag_elide_constructors = 2;
cxx_dialect = cxx1z;
lang_hooks.name = "GNU C++14"; /* Pretend C++14 till standarization. */
}
@@ -693,8 +693,11 @@ ocp_convert (tree type, tree expr, int convtype, int flags,
if (error_operand_p (e))
return error_mark_node;
- if (MAYBE_CLASS_TYPE_P (type) && (convtype & CONV_FORCE_TEMP))
- /* We need a new temporary; don't take this shortcut. */;
+ if (MAYBE_CLASS_TYPE_P (type) && (convtype & CONV_FORCE_TEMP)
+ && !(flag_elide_constructors >= 2
+ && TREE_CODE (e) == TARGET_EXPR))
+ /* We need a new temporary; don't take this shortcut. But in C++17, don't
+ force a temporary if we already have one. */;
else if (same_type_ignoring_top_level_qualifiers_p (type, TREE_TYPE (e)))
{
if (same_type_p (type, TREE_TYPE (e)))
new file mode 100644
@@ -0,0 +1,16 @@
+// { dg-options -std=c++1z }
+
+struct A
+{
+ A();
+ A(const A&) = delete;
+};
+
+bool b;
+A a = A();
+A a1 = b ? A() : A();
+A a2 = (42, A());
+
+A f();
+A a3 = f();
+A a4 = b ? A() : f();