From c11e39b0bdfc580582012fe56f0cce1b84f064f4 Mon Sep 17 00:00:00 2001 From: Jonathan Wakely Date: Mon, 23 May 2011 08:15:16 +0000 Subject: re PR c++/18016 (Warn about member variables initialized with itself) 2011-05-23 Jonathan Wakely PR c++/18016 * init.c (perform_member_init): Check for self-initialization. From-SVN: r174058 --- gcc/cp/init.c | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'gcc/cp/init.c') diff --git a/gcc/cp/init.c b/gcc/cp/init.c index 7d7adbe..5f30275 100644 --- a/gcc/cp/init.c +++ b/gcc/cp/init.c @@ -501,6 +501,17 @@ perform_member_init (tree member, tree init) if (decl == error_mark_node) return; + if (warn_init_self && init && TREE_CODE (init) == TREE_LIST + && TREE_CHAIN (init) == NULL_TREE) + { + tree val = TREE_VALUE (init); + 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), + OPT_Wuninitialized, "%qD is initialized with itself", + member); + } + if (init == void_type_node) { /* mem() means value-initialization. */ -- cgit v1.1