From: Jason Merrill Date: Mon, 9 May 2011 17:34:44 +0000 (-0400) Subject: re PR c++/34772 (self-initialisation does not silence uninitialised warnings (-Winit... X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=03808d178a46df619f8470211c4cff9946a51fd4;p=gcc.git re PR c++/34772 (self-initialisation does not silence uninitialised warnings (-Winit-self ignored)) PR c++/34772 * decl.c (initialize_local_var): Use DECL_INITIAL for simple initialization. From-SVN: r173582 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 17116e00b61..4c4036ab3b9 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2011-05-09 Jason Merrill + + PR c++/34772 + * decl.c (initialize_local_var): Use DECL_INITIAL for simple + initialization. + 2011-05-08 Ville Voutilainen Implement final/override for member functions. diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index c139f3f0ba4..c255e16c6da 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -5689,21 +5689,32 @@ initialize_local_var (tree decl, tree init) /* Perform the initialization. */ if (init) { - int saved_stmts_are_full_exprs_p; + if (TREE_CODE (init) == INIT_EXPR + && !TREE_SIDE_EFFECTS (TREE_OPERAND (init, 1))) + { + /* Stick simple initializers in DECL_INITIAL so that + -Wno-init-self works (c++/34772). */ + gcc_assert (TREE_OPERAND (init, 0) == decl); + DECL_INITIAL (decl) = TREE_OPERAND (init, 1); + } + else + { + int saved_stmts_are_full_exprs_p; - /* If we're only initializing a single object, guard the destructors - of any temporaries used in its initializer with its destructor. - This isn't right for arrays because each element initialization is - a full-expression. */ - if (cleanup && TREE_CODE (type) != ARRAY_TYPE) - wrap_temporary_cleanups (init, cleanup); + /* If we're only initializing a single object, guard the + destructors of any temporaries used in its initializer with + its destructor. This isn't right for arrays because each + element initialization is a full-expression. */ + if (cleanup && TREE_CODE (type) != ARRAY_TYPE) + wrap_temporary_cleanups (init, cleanup); - gcc_assert (building_stmt_tree ()); - saved_stmts_are_full_exprs_p = stmts_are_full_exprs_p (); - current_stmt_tree ()->stmts_are_full_exprs_p = 1; - finish_expr_stmt (init); - current_stmt_tree ()->stmts_are_full_exprs_p = - saved_stmts_are_full_exprs_p; + gcc_assert (building_stmt_tree ()); + saved_stmts_are_full_exprs_p = stmts_are_full_exprs_p (); + current_stmt_tree ()->stmts_are_full_exprs_p = 1; + finish_expr_stmt (init); + current_stmt_tree ()->stmts_are_full_exprs_p = + saved_stmts_are_full_exprs_p; + } } /* Set this to 0 so we can tell whether an aggregate which was diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 5b72fc5d6c6..b30addc7390 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,14 @@ +2011-05-09 Jason Merrill + + * gcc.dg/gcc.dg/uninit-D.c: Move to c-c++-common. + * gcc.dg/gcc.dg/uninit-D-O0.c: Move to c-c++-common. + * gcc.dg/gcc.dg/uninit-E.c: Move to c-c++-common. + * gcc.dg/gcc.dg/uninit-E-O0.c: Move to c-c++-common. + * gcc.dg/gcc.dg/uninit-F.c: Move to c-c++-common. + * gcc.dg/gcc.dg/uninit-F-O0.c: Move to c-c++-common. + * gcc.dg/gcc.dg/uninit-G.c: Move to c-c++-common. + * gcc.dg/gcc.dg/uninit-G-O0.c: Move to c-c++-common. + 2011-05-08 Ville Voutilainen * g++.dg/inherit/virtual9.C: New. diff --git a/gcc/testsuite/c-c++-common/uninit-D-O0.c b/gcc/testsuite/c-c++-common/uninit-D-O0.c new file mode 100644 index 00000000000..e63cb80aee0 --- /dev/null +++ b/gcc/testsuite/c-c++-common/uninit-D-O0.c @@ -0,0 +1,9 @@ +/* Test we do not warn about initializing variable with self. */ +/* { dg-do compile } */ +/* { dg-options "-Wuninitialized" } */ + +int f() +{ + int i = i; + return i; +} diff --git a/gcc/testsuite/c-c++-common/uninit-D.c b/gcc/testsuite/c-c++-common/uninit-D.c new file mode 100644 index 00000000000..ea957e49e98 --- /dev/null +++ b/gcc/testsuite/c-c++-common/uninit-D.c @@ -0,0 +1,9 @@ +/* Test we do not warn about initializing variable with self. */ +/* { dg-do compile } */ +/* { dg-options "-O -Wuninitialized" } */ + +int f() +{ + int i = i; + return i; +} diff --git a/gcc/testsuite/c-c++-common/uninit-E-O0.c b/gcc/testsuite/c-c++-common/uninit-E-O0.c new file mode 100644 index 00000000000..2cc2459663d --- /dev/null +++ b/gcc/testsuite/c-c++-common/uninit-E-O0.c @@ -0,0 +1,9 @@ +/* Test we do warn about initializing variable with self when -Winit-self is supplied. */ +/* { dg-do compile } */ +/* { dg-options "-Wuninitialized -Winit-self" } */ + +int f() +{ + int i = i; /* { dg-warning "i" "uninitialized variable warning" } */ + return i; +} diff --git a/gcc/testsuite/c-c++-common/uninit-E.c b/gcc/testsuite/c-c++-common/uninit-E.c new file mode 100644 index 00000000000..eb356c3ee0d --- /dev/null +++ b/gcc/testsuite/c-c++-common/uninit-E.c @@ -0,0 +1,9 @@ +/* Test we do warn about initializing variable with self when -Winit-self is supplied. */ +/* { dg-do compile } */ +/* { dg-options "-O -Wuninitialized -Winit-self" } */ + +int f() +{ + int i = i; /* { dg-warning "i" "uninitialized variable warning" } */ + return i; +} diff --git a/gcc/testsuite/c-c++-common/uninit-F-O0.c b/gcc/testsuite/c-c++-common/uninit-F-O0.c new file mode 100644 index 00000000000..737cc65007e --- /dev/null +++ b/gcc/testsuite/c-c++-common/uninit-F-O0.c @@ -0,0 +1,9 @@ +/* Test we do warn about initializing variable with self in the initialization. */ +/* { dg-do compile } */ +/* { dg-options "-Wuninitialized" } */ + +int f() +{ + int i = i + 1; /* { dg-warning "i" "uninitialized variable warning" } */ + return i; +} diff --git a/gcc/testsuite/c-c++-common/uninit-F.c b/gcc/testsuite/c-c++-common/uninit-F.c new file mode 100644 index 00000000000..1dbb365e5b7 --- /dev/null +++ b/gcc/testsuite/c-c++-common/uninit-F.c @@ -0,0 +1,9 @@ +/* Test we do warn about initializing variable with self in the initialization. */ +/* { dg-do compile } */ +/* { dg-options "-O -Wuninitialized" } */ + +int f() +{ + int i = i + 1; /* { dg-warning "i" "uninitialized variable warning" } */ + return i; +} diff --git a/gcc/testsuite/c-c++-common/uninit-G-O0.c b/gcc/testsuite/c-c++-common/uninit-G-O0.c new file mode 100644 index 00000000000..d6edffede66 --- /dev/null +++ b/gcc/testsuite/c-c++-common/uninit-G-O0.c @@ -0,0 +1,9 @@ +/* Test we do not warn about initializing variable with address of self in the initialization. */ +/* { dg-do compile } */ +/* { dg-options "-Wuninitialized" } */ + +void *f() +{ + void *i = &i; + return i; +} diff --git a/gcc/testsuite/c-c++-common/uninit-G.c b/gcc/testsuite/c-c++-common/uninit-G.c new file mode 100644 index 00000000000..08f5f532116 --- /dev/null +++ b/gcc/testsuite/c-c++-common/uninit-G.c @@ -0,0 +1,9 @@ +/* Test we do not warn about initializing variable with address of self in the initialization. */ +/* { dg-do compile } */ +/* { dg-options "-O -Wuninitialized" } */ + +void *f() +{ + void *i = &i; + return i; +} diff --git a/gcc/testsuite/gcc.dg/uninit-D-O0.c b/gcc/testsuite/gcc.dg/uninit-D-O0.c deleted file mode 100644 index e63cb80aee0..00000000000 --- a/gcc/testsuite/gcc.dg/uninit-D-O0.c +++ /dev/null @@ -1,9 +0,0 @@ -/* Test we do not warn about initializing variable with self. */ -/* { dg-do compile } */ -/* { dg-options "-Wuninitialized" } */ - -int f() -{ - int i = i; - return i; -} diff --git a/gcc/testsuite/gcc.dg/uninit-D.c b/gcc/testsuite/gcc.dg/uninit-D.c deleted file mode 100644 index ea957e49e98..00000000000 --- a/gcc/testsuite/gcc.dg/uninit-D.c +++ /dev/null @@ -1,9 +0,0 @@ -/* Test we do not warn about initializing variable with self. */ -/* { dg-do compile } */ -/* { dg-options "-O -Wuninitialized" } */ - -int f() -{ - int i = i; - return i; -} diff --git a/gcc/testsuite/gcc.dg/uninit-E-O0.c b/gcc/testsuite/gcc.dg/uninit-E-O0.c deleted file mode 100644 index 2cc2459663d..00000000000 --- a/gcc/testsuite/gcc.dg/uninit-E-O0.c +++ /dev/null @@ -1,9 +0,0 @@ -/* Test we do warn about initializing variable with self when -Winit-self is supplied. */ -/* { dg-do compile } */ -/* { dg-options "-Wuninitialized -Winit-self" } */ - -int f() -{ - int i = i; /* { dg-warning "i" "uninitialized variable warning" } */ - return i; -} diff --git a/gcc/testsuite/gcc.dg/uninit-E.c b/gcc/testsuite/gcc.dg/uninit-E.c deleted file mode 100644 index eb356c3ee0d..00000000000 --- a/gcc/testsuite/gcc.dg/uninit-E.c +++ /dev/null @@ -1,9 +0,0 @@ -/* Test we do warn about initializing variable with self when -Winit-self is supplied. */ -/* { dg-do compile } */ -/* { dg-options "-O -Wuninitialized -Winit-self" } */ - -int f() -{ - int i = i; /* { dg-warning "i" "uninitialized variable warning" } */ - return i; -} diff --git a/gcc/testsuite/gcc.dg/uninit-F-O0.c b/gcc/testsuite/gcc.dg/uninit-F-O0.c deleted file mode 100644 index 737cc65007e..00000000000 --- a/gcc/testsuite/gcc.dg/uninit-F-O0.c +++ /dev/null @@ -1,9 +0,0 @@ -/* Test we do warn about initializing variable with self in the initialization. */ -/* { dg-do compile } */ -/* { dg-options "-Wuninitialized" } */ - -int f() -{ - int i = i + 1; /* { dg-warning "i" "uninitialized variable warning" } */ - return i; -} diff --git a/gcc/testsuite/gcc.dg/uninit-F.c b/gcc/testsuite/gcc.dg/uninit-F.c deleted file mode 100644 index 1dbb365e5b7..00000000000 --- a/gcc/testsuite/gcc.dg/uninit-F.c +++ /dev/null @@ -1,9 +0,0 @@ -/* Test we do warn about initializing variable with self in the initialization. */ -/* { dg-do compile } */ -/* { dg-options "-O -Wuninitialized" } */ - -int f() -{ - int i = i + 1; /* { dg-warning "i" "uninitialized variable warning" } */ - return i; -} diff --git a/gcc/testsuite/gcc.dg/uninit-G-O0.c b/gcc/testsuite/gcc.dg/uninit-G-O0.c deleted file mode 100644 index d6edffede66..00000000000 --- a/gcc/testsuite/gcc.dg/uninit-G-O0.c +++ /dev/null @@ -1,9 +0,0 @@ -/* Test we do not warn about initializing variable with address of self in the initialization. */ -/* { dg-do compile } */ -/* { dg-options "-Wuninitialized" } */ - -void *f() -{ - void *i = &i; - return i; -} diff --git a/gcc/testsuite/gcc.dg/uninit-G.c b/gcc/testsuite/gcc.dg/uninit-G.c deleted file mode 100644 index 08f5f532116..00000000000 --- a/gcc/testsuite/gcc.dg/uninit-G.c +++ /dev/null @@ -1,9 +0,0 @@ -/* Test we do not warn about initializing variable with address of self in the initialization. */ -/* { dg-do compile } */ -/* { dg-options "-O -Wuninitialized" } */ - -void *f() -{ - void *i = &i; - return i; -}