From: jason Date: Wed, 28 Apr 2010 00:03:21 +0000 (+0000) Subject: PR c++/29043 X-Git-Url: http://git.sourceforge.jp/view?p=pf3gnuchains%2Fgcc-fork.git;a=commitdiff_plain;h=a0bbd07d6b449271335d4f4407b5945fb3c9bded PR c++/29043 * init.c (perform_member_init): check for uninitialized const or reference members, including array types. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@158817 138bc75d-0d04-0410-961f-82ee72b054a4 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 08746bae335..3935cc21241 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2010-04-27 Fabien Chêne + + PR c++/29043 + * init.c (perform_member_init): check for uninitialized const or + reference members, including array types. + 2010-04-24 Jason Merrill * tree.c (get_fns): Split out from get_first_fn. diff --git a/gcc/cp/init.c b/gcc/cp/init.c index e1dee1d10dc..57b874d5e4a 100644 --- a/gcc/cp/init.c +++ b/gcc/cp/init.c @@ -506,6 +506,7 @@ perform_member_init (tree member, tree init) { if (init == NULL_TREE) { + tree core_type; /* member traversal: note it leaves init NULL */ if (TREE_CODE (type) == REFERENCE_TYPE) permerror (DECL_SOURCE_LOCATION (current_function_decl), @@ -515,6 +516,11 @@ perform_member_init (tree member, tree init) permerror (DECL_SOURCE_LOCATION (current_function_decl), "uninitialized member %qD with % type %qT", member, type); + + core_type = strip_array_types (type); + if (CLASSTYPE_READONLY_FIELDS_NEED_INIT (core_type) + || CLASSTYPE_REF_FIELDS_NEED_INIT (core_type)) + diagnose_uninitialized_cst_or_ref_member (core_type, /*using_new=*/false); } else if (TREE_CODE (init) == TREE_LIST) /* There was an explicit member initialization. Do some work diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 1bd00ff9bef..ac3d6e63021 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2010-04-27 Fabien Chêne + + PR c++/29043 + * g++.dg/init/pr29043.C: New. + 2010-04-27 Jason Merrill * g++.dg/lookup/scoped5.C: Adjust. diff --git a/gcc/testsuite/g++.dg/init/pr29043.C b/gcc/testsuite/g++.dg/init/pr29043.C new file mode 100644 index 00000000000..6ed31b5d6b5 --- /dev/null +++ b/gcc/testsuite/g++.dg/init/pr29043.C @@ -0,0 +1,52 @@ +// PR c++/29043 +// { dg-do compile } + +struct S +{ + int const i; // { dg-message "should be initialized" } +}; + +class C +{ +public: + C() {} // { dg-error "uninitialized const member" } + S s; +}; + +struct S2 +{ + int& ref; // { dg-message "should be initialized" } +}; + +class C2 +{ +public: + C2() {} // { dg-error "uninitialized reference member" } + S2 s; +}; + +class C3 +{ + C3() { } + struct s { + const int i; + }; +}; + +struct S4 +{ + int const i; // { dg-message "should be initialized" } +}; + +struct C4 +{ + C4() {} // { dg-error "uninitialized const member" } + S4 s4[ 1 ]; +}; + +struct C5 +{ + C5() {} // { dg-message "uninitialized" } + int const iit[ 1 ]; +}; +