diff options
-rw-r--r-- | gcc/c/c-typeck.cc | 19 | ||||
-rw-r--r-- | gcc/testsuite/c-c++-common/Waddress-7.c | 22 |
2 files changed, 32 insertions, 9 deletions
diff --git a/gcc/c/c-typeck.cc b/gcc/c/c-typeck.cc index 43a910d..33d1e84 100644 --- a/gcc/c/c-typeck.cc +++ b/gcc/c/c-typeck.cc @@ -11738,18 +11738,19 @@ maybe_warn_for_null_address (location_t loc, tree op, tree_code code) || from_macro_expansion_at (loc)) return; + bool w; if (code == EQ_EXPR) - warning_at (loc, OPT_Waddress, - "the comparison will always evaluate as %<false%> " - "for the address of %qE will never be NULL", - op); + w = warning_at (loc, OPT_Waddress, + "the comparison will always evaluate as %<false%> " + "for the address of %qE will never be NULL", + op); else - warning_at (loc, OPT_Waddress, - "the comparison will always evaluate as %<true%> " - "for the address of %qE will never be NULL", - op); + w = warning_at (loc, OPT_Waddress, + "the comparison will always evaluate as %<true%> " + "for the address of %qE will never be NULL", + op); - if (DECL_P (op)) + if (w && DECL_P (op)) inform (DECL_SOURCE_LOCATION (op), "%qD declared here", op); } diff --git a/gcc/testsuite/c-c++-common/Waddress-7.c b/gcc/testsuite/c-c++-common/Waddress-7.c new file mode 100644 index 0000000..1799485 --- /dev/null +++ b/gcc/testsuite/c-c++-common/Waddress-7.c @@ -0,0 +1,22 @@ +/* PR c/106947 */ +/* { dg-do compile } */ +/* { dg-options "-Waddress" } */ + +#ifndef __cplusplus +# define bool _Bool +#endif + +#pragma GCC diagnostic ignored "-Waddress" +int s; /* { dg-bogus "declared" } */ +bool e = &s; +int +main () +{ + int error = 0; + { + bool e1 = &s; + if (!e1) + error = 1; + } + return error; +} |