From ebb526f950a667e2bef588325e9a5f7bfb80ed09 Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Mon, 27 Dec 2010 13:54:30 +0100 Subject: [PATCH] re PR c++/46626 (simple use of virtual methods causes pure virtual method call in c++0x mode) PR c++/46626 * semantics.c (build_data_member_initialization): For CLEANUP_STMT recurse into CLEANUP_BODY. * g++.dg/cpp0x/constexpr-base4.C: New test. From-SVN: r168271 --- gcc/cp/ChangeLog | 6 ++++++ gcc/cp/semantics.c | 24 +++++++++++++++++++----- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/g++.dg/cpp0x/constexpr-base4.C | 28 ++++++++++++++++++++++++++++ 4 files changed, 58 insertions(+), 5 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp0x/constexpr-base4.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 09e4353..b8247b4 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2010-12-27 Jakub Jelinek + + PR c++/46626 + * semantics.c (build_data_member_initialization): For CLEANUP_STMT + recurse into CLEANUP_BODY. + 2010-12-25 Kai Tietz PR c++/15774 diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c index 25b9932..93493fb 100644 --- a/gcc/cp/semantics.c +++ b/gcc/cp/semantics.c @@ -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 diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 2e7a079..cf8ff72 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2010-12-27 Jakub Jelinek + + PR c++/46626 + * g++.dg/cpp0x/constexpr-base4.C: New test. + 2010-12-26 Nicola Pero * 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 index 0000000..ce23cb9 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-base4.C @@ -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; +} -- 2.7.4