@@ -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
new file mode 100644
@@ -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;
+}
new file mode 100644
@@ -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;
+}
new file mode 100644
@@ -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;
+}
new file mode 100644
@@ -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;
+}
new file mode 100644
@@ -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;
+}
new file mode 100644
@@ -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;
+}
new file mode 100644
@@ -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;
+}
new file mode 100644
@@ -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;
+}
deleted file mode 100644
@@ -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;
-}
deleted file mode 100644
@@ -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;
-}
deleted file mode 100644
@@ -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;
-}
deleted file mode 100644
@@ -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;
-}
deleted file mode 100644
@@ -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;
-}
deleted file mode 100644
@@ -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;
-}
deleted file mode 100644
@@ -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;
-}
deleted file mode 100644
@@ -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;
-}