From patchwork Wed Jan 2 20:56:11 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: C++ PATCH for c++/54325 (wrong error initializing abstract base class) X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 209147 Message-Id: <50E49EEB.5050609@redhat.com> To: Paolo Carlini Cc: gcc-patches List Date: Wed, 02 Jan 2013 15:56:11 -0500 From: Jason Merrill List-Id: Fixed thus. For a user-provided default constructor we don't need to play with zeroing the object first, so we can use the normal logic that works properly for protected access. Tested x86_64-pc-linux-gnu, applying to trunk and 4.7. commit 0ebf6baa1f5f27bd96db44514425075cad2cbd97 Author: Jason Merrill Date: Wed Jan 2 15:31:02 2013 -0500 PR c++/54325 * call.c (build_new_method_call_1): Don't use build_value_init for user-provided default constructors. diff --git a/gcc/cp/call.c b/gcc/cp/call.c index bba5d9f..ad39637 100644 --- a/gcc/cp/call.c +++ b/gcc/cp/call.c @@ -7534,6 +7534,9 @@ build_new_method_call_1 (tree instance, tree fns, vec **args, build_special_member_call. */ if (CONSTRUCTOR_NELTS (init_list) == 0 && TYPE_HAS_DEFAULT_CONSTRUCTOR (basetype) + /* For a user-provided default constructor, use the normal + mechanisms so that protected access works. */ + && !type_has_user_provided_default_constructor (basetype) && !processing_template_decl) init = build_value_init (basetype, complain); diff --git a/gcc/testsuite/g++.dg/cpp0x/initlist-protected.C b/gcc/testsuite/g++.dg/cpp0x/initlist-protected.C new file mode 100644 index 0000000..fb5cc6a --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/initlist-protected.C @@ -0,0 +1,23 @@ +// PR c++/54325 +// { dg-options -std=c++11 } + +class base +{ + protected: + base() + {} +}; + +class derived : public base +{ + public: + derived() + : base{} // <-- Note the c++11 curly brace syntax + {} +}; + +int main() +{ + derived d1; + return 0; +}