GCC Bugzilla – Attachment 36706 Details for
Bug 19808
miss a warning about uninitialized member usage in member initializer list in constructor
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
First version of patch for PR19808
19808.diff (text/plain), 3.48 KB, created by
Anthony Brandon
on 2015-11-14 09:52:07 UTC
(
hide
)
Description:
First version of patch for PR19808
Filename:
MIME Type:
Creator:
Anthony Brandon
Created:
2015-11-14 09:52:07 UTC
Size:
3.48 KB
patch
obsolete
>diff --git a/gcc/cp/init.c b/gcc/cp/init.c >index 2e11acb..680ca83 100644 >--- a/gcc/cp/init.c >+++ b/gcc/cp/init.c >@@ -38,7 +38,7 @@ static tree finish_init_stmts (bool, tree, tree); > static void construct_virtual_base (tree, tree); > static void expand_aggr_init_1 (tree, tree, tree, tree, int, tsubst_flags_t); > static void expand_default_init (tree, tree, tree, tree, int, tsubst_flags_t); >-static void perform_member_init (tree, tree); >+static void perform_member_init (tree, tree, vec<tree> *); > static int member_init_ok_or_else (tree, tree, tree); > static void expand_virtual_init (tree, tree); > static tree sort_mem_initializers (tree, tree); >@@ -596,12 +596,46 @@ get_nsdmi (tree member, bool in_ctor) > return init; > } > >+/* Search for a usage of an uninitialized member of the current class. >+ For use in perform_member_init. */ >+ >+static tree >+find_uninitialized_member (tree *tp, int *walk_subtrees, void *data) >+{ >+ vec<tree> *inited = (vec<tree> *)data; >+ if (TREE_CODE (*tp) == COMPONENT_REF) >+ { >+ /* Only look at the top most COMPONENT_REF to ignore members of parent >+ classes or structs. */ >+ if (!(TREE_OPERAND (*tp, 0) == current_class_ref)) >+ { >+ *walk_subtrees = 0; >+ return NULL_TREE; >+ } >+ /* Search the vector of previously seen members to determine if one is >+ being used before being initialized. */ >+ tree ptr; >+ bool found = false; >+ for (int ix = 0; inited->iterate (ix, &ptr); ix++) >+ { >+ if (ptr == TREE_OPERAND(*tp,1)) >+ { >+ found = true; >+ break; >+ } >+ } >+ if (!found) >+ return *tp; >+ } >+ return NULL_TREE; >+} >+ > /* Initialize MEMBER, a FIELD_DECL, with INIT, a TREE_LIST of > arguments. If TREE_LIST is void_type_node, an empty initializer > list was given; if NULL_TREE no initializer was given. */ > > static void >-perform_member_init (tree member, tree init) >+perform_member_init (tree member, tree init, vec<tree> *inited) > { > tree decl; > tree type = TREE_TYPE (member); >@@ -638,10 +672,25 @@ perform_member_init (tree member, tree init) > val = TREE_OPERAND (val, 0); > if (TREE_CODE (val) == COMPONENT_REF && TREE_OPERAND (val, 1) == member > && TREE_OPERAND (val, 0) == current_class_ref) >- warning_at (DECL_SOURCE_LOCATION (current_function_decl), >+ warning_at (EXPR_LOCATION (val), > OPT_Winit_self, "%qD is initialized with itself", > member); > } >+ if (warn_uninitialized && init && TREE_CODE (init) == TREE_LIST >+ && TREE_CHAIN (init) == NULL_TREE) >+ { >+ tree res = walk_tree_without_duplicates(&init, find_uninitialized_member, >+ inited); >+ if (res != NULL_TREE && !(TREE_CODE (res) == COMPONENT_REF && >+ TREE_OPERAND (res, 1) == member && >+ TREE_OPERAND (res, 0) == current_class_ref)) >+ { >+ warning_at (EXPR_LOCATION(res), >+ OPT_Wuninitialized, >+ "%qD is initialized with uninitialized field %qD", >+ member, TREE_OPERAND(res,1)); >+ } >+ } > > if (init == void_type_node) > { >@@ -1170,12 +1219,16 @@ emit_mem_initializers (tree mem_inits) > initialize_vtbl_ptrs (current_class_ptr); > > /* Initialize the data members. */ >+ vec<tree> initialized; >+ initialized.create(0); > while (mem_inits) > { > perform_member_init (TREE_PURPOSE (mem_inits), >- TREE_VALUE (mem_inits)); >+ TREE_VALUE (mem_inits), &initialized); >+ initialized.safe_push(TREE_PURPOSE(mem_inits)); > mem_inits = TREE_CHAIN (mem_inits); > } >+ initialized.release(); > } > > /* Returns the address of the vtable (i.e., the value that should be
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 19808
:
36706
|
36851