diff options
-rw-r--r-- | gcc/c/c-parser.cc | 2 | ||||
-rw-r--r-- | gcc/cp/decl.cc | 2 | ||||
-rw-r--r-- | gcc/testsuite/c-c++-common/Winit-self3.c | 36 | ||||
-rw-r--r-- | gcc/testsuite/c-c++-common/Winit-self4.c | 36 | ||||
-rw-r--r-- | gcc/testsuite/c-c++-common/Winit-self5.c | 36 |
5 files changed, 110 insertions, 2 deletions
diff --git a/gcc/c/c-parser.cc b/gcc/c/c-parser.cc index 3e2109b..a698506 100644 --- a/gcc/c/c-parser.cc +++ b/gcc/c/c-parser.cc @@ -5701,7 +5701,7 @@ c_parser_initializer (c_parser *parser, tree decl) && !DECL_EXTERNAL (decl) && !TREE_STATIC (decl) && ret.value == decl - && !warn_init_self) + && !warning_enabled_at (DECL_SOURCE_LOCATION (decl), OPT_Winit_self)) suppress_warning (decl, OPT_Winit_self); if (TREE_CODE (ret.value) != STRING_CST && (TREE_CODE (ret.value) != COMPOUND_LITERAL_EXPR diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc index 66e7d9f..6b1c4a2 100644 --- a/gcc/cp/decl.cc +++ b/gcc/cp/decl.cc @@ -8407,7 +8407,7 @@ cp_finish_decl (tree decl, tree init, bool init_const_expr_p, if (!DECL_EXTERNAL (decl) && !TREE_STATIC (decl) && decl == tree_strip_any_location_wrapper (init) - && !warn_init_self) + && !warning_enabled_at (DECL_SOURCE_LOCATION (decl), OPT_Winit_self)) suppress_warning (decl, OPT_Winit_self); } diff --git a/gcc/testsuite/c-c++-common/Winit-self3.c b/gcc/testsuite/c-c++-common/Winit-self3.c new file mode 100644 index 0000000..b83135f --- /dev/null +++ b/gcc/testsuite/c-c++-common/Winit-self3.c @@ -0,0 +1,36 @@ +/* PR c++/105593 */ +/* { dg-do compile } */ +/* { dg-options "-W -Wall" } */ + +void bar (int); + +static inline int +baz (void) +{ +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Winit-self" + int u = u; /* { dg-bogus "'u' is used uninitialized" } */ +#pragma GCC diagnostic pop + return u; +} + +void +foo (void) +{ + int u = baz (); + bar (u); +} + +static inline int +qux (void) +{ + int u = u; /* { dg-warning "'u' is used uninitialized" "" { target c++ } } */ + return u; /* { dg-message "'u' was declared here" "" { target c++ } .-1 } */ +} + +void +corge (void) +{ + int u = qux (); + bar (u); +} diff --git a/gcc/testsuite/c-c++-common/Winit-self4.c b/gcc/testsuite/c-c++-common/Winit-self4.c new file mode 100644 index 0000000..b38b7cc --- /dev/null +++ b/gcc/testsuite/c-c++-common/Winit-self4.c @@ -0,0 +1,36 @@ +/* PR c++/105593 */ +/* { dg-do compile } */ +/* { dg-options "-W -Wall -Winit-self" } */ + +void bar (int); + +static inline int +baz (void) +{ +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Winit-self" + int u = u; /* { dg-bogus "'u' is used uninitialized" } */ +#pragma GCC diagnostic pop + return u; +} + +void +foo (void) +{ + int u = baz (); + bar (u); +} + +static inline int +qux (void) +{ + int u = u; /* { dg-warning "'u' is used uninitialized" } */ + return u; /* { dg-message "'u' was declared here" "" { target *-*-* } .-1 } */ +} + +void +corge (void) +{ + int u = qux (); + bar (u); +} diff --git a/gcc/testsuite/c-c++-common/Winit-self5.c b/gcc/testsuite/c-c++-common/Winit-self5.c new file mode 100644 index 0000000..db2d9a1 --- /dev/null +++ b/gcc/testsuite/c-c++-common/Winit-self5.c @@ -0,0 +1,36 @@ +/* PR c++/105593 */ +/* { dg-do compile } */ +/* { dg-options "-W -Wall -Wno-init-self" } */ + +void bar (int); + +static inline int +baz (void) +{ +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Winit-self" + int u = u; /* { dg-bogus "'u' is used uninitialized" } */ +#pragma GCC diagnostic pop + return u; +} + +void +foo (void) +{ + int u = baz (); + bar (u); +} + +static inline int +qux (void) +{ + int u = u; /* { dg-bogus "'u' is used uninitialized" } */ + return u; +} + +void +corge (void) +{ + int u = qux (); + bar (u); +} |