re PR c++/34772 (self-initialisation does not silence uninitialised warnings (-Winit...
authorJason Merrill <jason@redhat.com>
Mon, 9 May 2011 17:34:44 +0000 (13:34 -0400)
committerJason Merrill <jason@gcc.gnu.org>
Mon, 9 May 2011 17:34:44 +0000 (13:34 -0400)
PR c++/34772
* decl.c (initialize_local_var): Use DECL_INITIAL for simple
initialization.

From-SVN: r173582

19 files changed:
gcc/cp/ChangeLog
gcc/cp/decl.c
gcc/testsuite/ChangeLog
gcc/testsuite/c-c++-common/uninit-D-O0.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/uninit-D.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/uninit-E-O0.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/uninit-E.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/uninit-F-O0.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/uninit-F.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/uninit-G-O0.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/uninit-G.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/uninit-D-O0.c [deleted file]
gcc/testsuite/gcc.dg/uninit-D.c [deleted file]
gcc/testsuite/gcc.dg/uninit-E-O0.c [deleted file]
gcc/testsuite/gcc.dg/uninit-E.c [deleted file]
gcc/testsuite/gcc.dg/uninit-F-O0.c [deleted file]
gcc/testsuite/gcc.dg/uninit-F.c [deleted file]
gcc/testsuite/gcc.dg/uninit-G-O0.c [deleted file]
gcc/testsuite/gcc.dg/uninit-G.c [deleted file]

index 17116e00b613ad73c240c1f95cae0caf3a875376..4c4036ab3b9aecfaaa358f6bd549bb3f109b5d20 100644 (file)
@@ -1,3 +1,9 @@
+2011-05-09  Jason Merrill  <jason@redhat.com>
+
+       PR c++/34772
+       * decl.c (initialize_local_var): Use DECL_INITIAL for simple
+       initialization.
+
 2011-05-08  Ville Voutilainen  <ville.voutilainen@gmail.com>
 
        Implement final/override for member functions.
index c139f3f0ba4642a8d99dd7fc928dd2bf73742d26..c255e16c6dacca6c7c0f371d4e9d3ee8b9660897 100644 (file)
@@ -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
index 5b72fc5d6c6cd4529cd597046ddc7a6e620c1221..b30addc7390937f09a3b354402fef0c360ba4444 100644 (file)
@@ -1,3 +1,14 @@
+2011-05-09  Jason Merrill  <jason@redhat.com>
+
+       * 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  <ville.voutilainen@gmail.com>
 
         * 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 (file)
index 0000000..e63cb80
--- /dev/null
@@ -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 (file)
index 0000000..ea957e4
--- /dev/null
@@ -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 (file)
index 0000000..2cc2459
--- /dev/null
@@ -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 (file)
index 0000000..eb356c3
--- /dev/null
@@ -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 (file)
index 0000000..737cc65
--- /dev/null
@@ -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 (file)
index 0000000..1dbb365
--- /dev/null
@@ -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 (file)
index 0000000..d6edffe
--- /dev/null
@@ -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 (file)
index 0000000..08f5f53
--- /dev/null
@@ -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 (file)
index e63cb80..0000000
+++ /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 (file)
index ea957e4..0000000
+++ /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 (file)
index 2cc2459..0000000
+++ /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 (file)
index eb356c3..0000000
+++ /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 (file)
index 737cc65..0000000
+++ /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 (file)
index 1dbb365..0000000
+++ /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 (file)
index d6edffe..0000000
+++ /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 (file)
index 08f5f53..0000000
+++ /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;
-}