PR c++/84441 - ICE with base initialized from ?:
authorJason Merrill <jason@redhat.com>
Tue, 27 Feb 2018 02:45:12 +0000 (21:45 -0500)
committerJason Merrill <jason@gcc.gnu.org>
Tue, 27 Feb 2018 02:45:12 +0000 (21:45 -0500)
* call.c (unsafe_copy_elision_p): Handle COND_EXPR.

From-SVN: r258022

gcc/cp/ChangeLog
gcc/cp/call.c
gcc/testsuite/g++.dg/cpp0x/elision3.C [new file with mode: 0644]

index fe5c7864f3a2d0e45cca0ee17ddef540da0a0e07..e34611324c44beb56123521092e47930a48d664a 100644 (file)
@@ -1,5 +1,8 @@
 2018-02-26  Jason Merrill  <jason@redhat.com>
 
+       PR c++/84441 - ICE with base initialized from ?:
+       * call.c (unsafe_copy_elision_p): Handle COND_EXPR.
+
        PR c++/84520 - ICE with generic lambda in NSDMI.
        * lambda.c (lambda_expr_this_capture): Don't look for fake NSDMI
        'this' in a generic lambda instantiation.
index c47befdbf7f88340290837ec352d47394868b2fa..11fe28292fb105c10e0937672d036efa60e8ec6d 100644 (file)
@@ -7580,6 +7580,15 @@ unsafe_copy_elision_p (tree target, tree exp)
   /* build_compound_expr pushes COMPOUND_EXPR inside TARGET_EXPR.  */
   while (TREE_CODE (init) == COMPOUND_EXPR)
     init = TREE_OPERAND (init, 1);
+  if (TREE_CODE (init) == COND_EXPR)
+    {
+      /* We'll end up copying from each of the arms of the COND_EXPR directly
+        into the target, so look at them. */
+      if (tree op = TREE_OPERAND (init, 1))
+       if (unsafe_copy_elision_p (target, op))
+         return true;
+      return unsafe_copy_elision_p (target, TREE_OPERAND (init, 2));
+    }
   return (TREE_CODE (init) == AGGR_INIT_EXPR
          && !AGGR_INIT_VIA_CTOR_P (init));
 }
diff --git a/gcc/testsuite/g++.dg/cpp0x/elision3.C b/gcc/testsuite/g++.dg/cpp0x/elision3.C
new file mode 100644 (file)
index 0000000..7c5c8b9
--- /dev/null
@@ -0,0 +1,21 @@
+// PR c++/84441
+// { dg-do compile { target c++11 } }
+
+struct B {
+  int *b;
+};
+struct A {
+  B b;
+  A (A &&);
+};
+struct C {
+  A c;
+  int d;
+};
+C bar ();
+struct D : C {
+  D ()
+    : C (0 ? bar () : bar ())
+  {}
+};
+D d;