re PR c++/18016 (Warn about member variables initialized with itself)
2011-05-23 Jonathan Wakely <jwakely.gcc@gmail.com> PR c++/18016 * init.c (perform_member_init): Check for self-initialization. From-SVN: r174058
This commit is contained in:
parent
bc69f7ffb5
commit
c11e39b0bd
@ -1,3 +1,8 @@
|
||||
2011-05-23 Jonathan Wakely <jwakely.gcc@gmail.com>
|
||||
|
||||
PR c++/18016
|
||||
* init.c (perform_member_init): Check for self-initialization.
|
||||
|
||||
2011-05-22 Jason Merrill <jason@redhat.com>
|
||||
|
||||
PR c++/48647
|
||||
|
@ -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. */
|
||||
|
@ -1,3 +1,8 @@
|
||||
2011-05-23 Jonathan Wakely <jwakely.gcc@gmail.com>
|
||||
|
||||
PR c++/18016
|
||||
* g++.dg/warn/pr18016.C: New.
|
||||
|
||||
2011-05-23 Tom de Vries <tom@codesourcery.com>
|
||||
|
||||
PR target/45098
|
||||
|
11
gcc/testsuite/g++.dg/warn/pr18016.C
Normal file
11
gcc/testsuite/g++.dg/warn/pr18016.C
Normal file
@ -0,0 +1,11 @@
|
||||
/* { dg-do compile } */
|
||||
/* { dg-options "-Wuninitialized -Winit-self" } */
|
||||
|
||||
class X {
|
||||
int i;
|
||||
X() : i(i) { } // { dg-warning "initialized with itself" }
|
||||
X(int i) : i(i) { }
|
||||
X(const X& x) : i(x.i) { }
|
||||
};
|
||||
|
||||
// { dg-prune-output "In constructor" }
|
Loading…
Reference in New Issue
Block a user