OSDN Git Service

PR c++/46626
authorjakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4>
Mon, 27 Dec 2010 12:54:30 +0000 (12:54 +0000)
committerjakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4>
Mon, 27 Dec 2010 12:54:30 +0000 (12:54 +0000)
* semantics.c (build_data_member_initialization): For CLEANUP_STMT
recurse into CLEANUP_BODY.

* g++.dg/cpp0x/constexpr-base4.C: New test.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@168271 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/cp/ChangeLog
gcc/cp/semantics.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/cpp0x/constexpr-base4.C [new file with mode: 0644]

index 09e4353..b8247b4 100644 (file)
@@ -1,3 +1,9 @@
+2010-12-27  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c++/46626
+       * semantics.c (build_data_member_initialization): For CLEANUP_STMT
+       recurse into CLEANUP_BODY.
+
 2010-12-25  Kai Tietz  <kai.tietz@onevision.com>
 
        PR c++/15774
index 25b9932..93493fb 100644 (file)
@@ -5440,11 +5440,25 @@ build_data_member_initialization (tree t, VEC(constructor_elt,gc) **vec)
   if (t == error_mark_node)
     return false;
   if (TREE_CODE (t) == CLEANUP_STMT)
-    /* We can't see a CLEANUP_STMT in a constructor for a literal class,
-       but we can in a constexpr constructor for a non-literal class.  Just
-       ignore it; either all the initialization will be constant, in which
-       case the cleanup can't run, or it can't be constexpr.  */
-    return true;
+    {
+      /* We can't see a CLEANUP_STMT in a constructor for a literal class,
+        but we can in a constexpr constructor for a non-literal class.  Just
+        ignore it; either all the initialization will be constant, in which
+        case the cleanup can't run, or it can't be constexpr.
+        Still recurse into CLEANUP_BODY.  */
+      t = CLEANUP_BODY (t);
+      if (TREE_CODE (t) == STATEMENT_LIST)
+       {
+         tree_stmt_iterator i;
+         for (i = tsi_start (t); !tsi_end_p (i); tsi_next (&i))
+           {
+             if (! build_data_member_initialization (tsi_stmt (i), vec))
+               return false;
+           }
+         return true;
+       }
+      return build_data_member_initialization (t, vec);
+    }
   if (TREE_CODE (t) == CONVERT_EXPR)
     t = TREE_OPERAND (t, 0);
   if (TREE_CODE (t) == INIT_EXPR
index 2e7a079..cf8ff72 100644 (file)
@@ -1,3 +1,8 @@
+2010-12-27  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c++/46626
+       * g++.dg/cpp0x/constexpr-base4.C: New test.
+
 2010-12-26  Nicola Pero  <nicola.pero@meta-innovation.com>
 
        * objc.dg/gnu-api-2-class.m: Xfail the test on Apple Darwin m64.
diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-base4.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-base4.C
new file mode 100644 (file)
index 0000000..ce23cb9
--- /dev/null
@@ -0,0 +1,28 @@
+// PR c++/46626
+// { dg-do run }
+// { dg-options "-std=c++0x" }
+
+struct A
+{
+  virtual void f () = 0;
+  virtual ~A () { }
+};
+
+struct B : A
+{
+  virtual void f () { }
+};
+
+static void
+foo (A *a)
+{
+  a->f ();
+}
+
+int
+main ()
+{
+  B b;
+  foo (&b);
+  return 0;
+}