From 6132bdd72ebbcea9621519330d07ccb9a8c29f9d Mon Sep 17 00:00:00 2001 From: Jason Merrill Date: Fri, 23 Sep 2011 17:30:48 -0400 Subject: Core 234 - allow const objects with no initializer or user-provided default... Core 234 - allow const objects with no initializer or user-provided default constructor if the defaulted constructor initializes all the subobjects. PR c++/20039 PR c++/42844 * class.c (default_init_uninitialized_part): New. * cp-tree.h: Declare it. * decl.c (check_for_uninitialized_const_var): Use it. * init.c (perform_member_init): Likewise. (build_new_1): Likewise. * method.c (walk_field_subobs): Likewise. From-SVN: r179130 --- gcc/cp/decl.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'gcc/cp/decl.c') diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index 709deca..495d8a0 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -4899,15 +4899,16 @@ check_for_uninitialized_const_var (tree decl) if (TREE_CODE (decl) == VAR_DECL && TREE_CODE (type) != REFERENCE_TYPE && CP_TYPE_CONST_P (type) - && (!TYPE_NEEDS_CONSTRUCTING (type) - || !type_has_user_provided_default_constructor (type)) && !DECL_INITIAL (decl)) { + tree field = default_init_uninitialized_part (type); + if (!field) + return; + permerror (DECL_SOURCE_LOCATION (decl), "uninitialized const %qD", decl); - if (CLASS_TYPE_P (type) - && !type_has_user_provided_default_constructor (type)) + if (CLASS_TYPE_P (type)) { tree defaulted_ctor; @@ -4918,6 +4919,8 @@ check_for_uninitialized_const_var (tree decl) inform (DECL_SOURCE_LOCATION (defaulted_ctor), "constructor is not user-provided because it is " "explicitly defaulted in the class body"); + inform (0, "and the implicitly-defined constructor does not " + "initialize %q+#D", field); } } } -- cgit v1.1