diff options
author | Marek Polacek <polacek@redhat.com> | 2022-09-19 14:12:55 -0400 |
---|---|---|
committer | Marek Polacek <polacek@redhat.com> | 2022-09-19 14:19:26 -0400 |
commit | 2d9429d5c0f86f588bdfd85bb9e236d2be367d3f (patch) | |
tree | a1b970dc9763cf99f53e19ae20e5288285d1eeec /gcc/c | |
parent | de40fab2f32b03c3d8f69f72c7f1e38694f93d35 (diff) | |
download | gcc-2d9429d5c0f86f588bdfd85bb9e236d2be367d3f.zip gcc-2d9429d5c0f86f588bdfd85bb9e236d2be367d3f.tar.gz gcc-2d9429d5c0f86f588bdfd85bb9e236d2be367d3f.tar.bz2 |
c: Stray inform note with -Waddress [PR106947]
A trivial fix for maybe_warn_for_null_address where we print an
inform note without first checking the return value of a warning
call.
PR c/106947
gcc/c/ChangeLog:
* c-typeck.cc (maybe_warn_for_null_address): Don't emit stray
notes.
gcc/testsuite/ChangeLog:
* c-c++-common/Waddress-7.c: New test.
Diffstat (limited to 'gcc/c')
-rw-r--r-- | gcc/c/c-typeck.cc | 19 |
1 files changed, 10 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); } |