aboutsummaryrefslogtreecommitdiff
path: root/gcc/doc
diff options
context:
space:
mode:
authorMark Wielaard <mjw@redhat.com>2015-09-10 15:29:44 +0000
committerMark Wielaard <mark@gcc.gnu.org>2015-09-10 15:29:44 +0000
commitdbb68221b64c0174eeb22d878a8e078775ee73bf (patch)
treef34f064a585942929fce66827ae853b1f48d5357 /gcc/doc
parent0815fd250302b45a3aadd9b32d8559c7b47d86e4 (diff)
downloadgcc-dbb68221b64c0174eeb22d878a8e078775ee73bf.zip
gcc-dbb68221b64c0174eeb22d878a8e078775ee73bf.tar.gz
gcc-dbb68221b64c0174eeb22d878a8e078775ee73bf.tar.bz2
Warn when comparing nonnull arguments to NULL in a function.
If an argument is marked as nonnull then passing in a NULL argument will produce bad results even if the code checks against NULL. GCC might optimize such checks away so warn the user when the function contains such comparisons. nn.c: In function ‘foo’: nn.c:6:27: warning: nonnull argument ‘bar’ compared to NULL [-Wnonnull] void foo(void *bar) { if (!bar) abort(); } ^ gcc/ChangeLog * doc/invoke.texi (Wnonnull): Also warns when comparing against NULL. gcc/c/ChangeLog * c-typeck.c (build_binary_op): Check and warn when nonnull arg parm against NULL. gcc/cp/ChangeLog * typeck.c (cp_build_binary_op): Check and warn when nonnull arg parm against NULL. gcc/testsuite/ChangeLog * c-c++-common/nonnull-1.c: New test. From-SVN: r227649
Diffstat (limited to 'gcc/doc')
-rw-r--r--gcc/doc/invoke.texi3
1 files changed, 3 insertions, 0 deletions
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index 403cebe..518d689 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -3720,6 +3720,9 @@ formats that may yield only a two-digit year.
Warn about passing a null pointer for arguments marked as
requiring a non-null value by the @code{nonnull} function attribute.
+Also warns when comparing an argument marked with the @code{nonnull}
+function attribute against null inside the function.
+
@option{-Wnonnull} is included in @option{-Wall} and @option{-Wformat}. It
can be disabled with the @option{-Wno-nonnull} option.