------- Comment #9 from redi at gcc dot gnu dot org 2010-06-03 01:13 ------- I've been experimenting with this patch, which warns if there is a missing mem-initializer for a scalar.
It gives a false positive for cases were the member is assigned to in the constructor body, or otherwise initialized before use, but it's a start, and has already helped me find some missing mem-initializers in real code. --- c.opt.orig 2010-06-02 13:47:02.120129255 +0000 +++ c.opt 2010-06-02 13:07:51.944440072 +0000 @@ -304,6 +304,10 @@ C ObjC C++ ObjC++ Var(warn_main) Init(-1) Warning Warn about suspicious declarations of \"main\" +Wmeminit +C++ Var(warn_meminit) Init(-1) Warning +Warn about POD members which are not initialized in a constructor initialization list + Wmissing-braces C ObjC C++ ObjC++ Var(warn_missing_braces) Warning Warn about possibly missing braces around initializers --- c-opts.c.orig 2010-06-02 13:46:49.774040694 +0000 +++ c-opts.c 2010-06-02 13:11:57.829233564 +0000 @@ -492,6 +492,10 @@ cpp_opts->warn_invalid_pch = value; break; + case OPT_Wmeminit: + warn_meminit = value; + break; + case OPT_Wmissing_include_dirs: cpp_opts->warn_missing_include_dirs = value; break; --- cp/init.c.orig 2010-06-02 13:46:31.125713124 +0000 +++ cp/init.c 2010-06-02 13:21:01.473640135 +0000 @@ -424,6 +424,12 @@ tree decl; tree type = TREE_TYPE (member); + /* warn if there is no initializer for a POD member */ + if (warn_meminit && init == NULL_TREE && layout_pod_type_p (strip_array_types (type))) + warning_at (DECL_SOURCE_LOCATION (current_function_decl), OPT_Wmeminit, + "%qD is not initialized in the member initialization list", + member); + /* Effective C++ rule 12 requires that all data members be initialized. */ if (warn_ecpp && init == NULL_TREE && TREE_CODE (type) != ARRAY_TYPE) -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=2972