From 0ed4ab44f6f483b41ea21b0f85e1cc5e5acd5aac Mon Sep 17 00:00:00 2001 From: Jason Merrill Date: Thu, 6 Dec 2012 23:54:27 -0500 Subject: [PATCH] re PR c++/54325 (C++11 uniform initialization syntax for argument-less abstract base class constructor fails) PR c++/54325 * tree.c (build_aggr_init_expr): Don't check for abstract class. From-SVN: r194284 --- gcc/cp/ChangeLog | 4 ++++ gcc/cp/tree.c | 12 +++++------ gcc/testsuite/g++.dg/cpp0x/initlist-pure.C | 25 ++++++++++++++++++++++ gcc/testsuite/g++.dg/other/abstract3.C | 2 +- 4 files changed, 36 insertions(+), 7 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp0x/initlist-pure.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index a92ebe147c9..7bec9ca96ca 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,5 +1,9 @@ 2012-12-06 Jason Merrill + PR c++/54325 + * tree.c (build_aggr_init_expr): Don't check for abstract class. + (build_cplus_new): Check here instead. + PR c++/55058 * pt.c (tsubst): Keep the quals when looking through a typedef. diff --git a/gcc/cp/tree.c b/gcc/cp/tree.c index 28ff0f20eb1..ca82f75eb64 100644 --- a/gcc/cp/tree.c +++ b/gcc/cp/tree.c @@ -407,18 +407,13 @@ build_aggr_init_array (tree return_type, tree fn, tree slot, int nargs, callable. */ tree -build_aggr_init_expr (tree type, tree init, tsubst_flags_t complain) +build_aggr_init_expr (tree type, tree init, tsubst_flags_t /*complain*/) { tree fn; tree slot; tree rval; int is_ctor; - /* Make sure that we're not trying to create an instance of an - abstract class. */ - if (abstract_virtuals_error_sfinae (NULL_TREE, type, complain)) - return error_mark_node; - if (TREE_CODE (init) == CALL_EXPR) fn = CALL_EXPR_FN (init); else if (TREE_CODE (init) == AGGR_INIT_EXPR) @@ -477,6 +472,11 @@ build_cplus_new (tree type, tree init, tsubst_flags_t complain) tree rval = build_aggr_init_expr (type, init, complain); tree slot; + /* Make sure that we're not trying to create an instance of an + abstract class. */ + if (abstract_virtuals_error_sfinae (NULL_TREE, type, complain)) + return error_mark_node; + if (TREE_CODE (rval) == AGGR_INIT_EXPR) slot = AGGR_INIT_EXPR_SLOT (rval); else if (TREE_CODE (rval) == CALL_EXPR diff --git a/gcc/testsuite/g++.dg/cpp0x/initlist-pure.C b/gcc/testsuite/g++.dg/cpp0x/initlist-pure.C new file mode 100644 index 00000000000..63c341c12ca --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/initlist-pure.C @@ -0,0 +1,25 @@ +// PR c++/54325 +// { dg-options -std=c++11 } + +class Base { +public: + Base() {}; + virtual ~Base() {}; + + virtual void do_stuff() = 0; +}; + +class Derived: public Base { +public: + Derived() : Base{} {}; + virtual ~Derived() {}; + + virtual void do_stuff() {}; +}; + +int +main() { + Derived d; + + return 0; +} diff --git a/gcc/testsuite/g++.dg/other/abstract3.C b/gcc/testsuite/g++.dg/other/abstract3.C index 528b7d79360..95e293e501b 100644 --- a/gcc/testsuite/g++.dg/other/abstract3.C +++ b/gcc/testsuite/g++.dg/other/abstract3.C @@ -8,5 +8,5 @@ struct A // { dg-message "note" } struct B { A a; // { dg-error "abstract" } - B() : a() {} // { dg-error "abstract" } + B() : a() {} }; -- 2.30.2