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 <ja...@redhat.com>
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<tree, va_gc> **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;
+}