[Bug c++/24745] New: unpleasant warning for "if (NULL)"
mec at google dot com
gcc-bugzilla@gcc.gnu.org
Tue Nov 8 23:19:00 GMT 2005
C++ programs with "if (NULL)" generate an unpleasant warning even with default
compiler options. Code with "if (NULL)" comes from of macro expansion or
auto-generated code.
Warnings are a matter of taste so I won't ask "make all the warnings match my
taste", but I do petition you to revisit which of these lines should generate
warnings and apply your own taste.
This patch looks like the last time these warnings were modified:
http://gcc.gnu.org/ml/gcc-patches/2005-01/msg02230.html
Mark Mitchell, C++ PATCH: PR 19457 a PR 19349
Test program:
int foo() {
if (__null) return -1;
if (!__null) ; else return -1;
if (__null == __null) ; else return -1;
if (__null != __null) return -1;
if (__null == __null) ; else return -1;
if (__null != 0) ; else return -1;
return 0;
}
int main() {
return foo() == 0;
}
Warnings shown:
hollerith:~/null-arithmetic$ /home/mec/gcc-4.0.2/install/bin/gcc -c
null-arithmetic.cc
null-arithmetic.cc: In function 'int foo()':
null-arithmetic.cc:2: warning: converting to non-pointer type 'bool' from NULL
null-arithmetic.cc:3: warning: converting to non-pointer type 'bool' from NULL
null-arithmetic.cc:4: warning: NULL used in arithmetic
null-arithmetic.cc:5: warning: NULL used in arithmetic
null-arithmetic.cc:6: warning: NULL used in arithmetic
null-arithmetic.cc:7: warning: NULL used in arithmetic
hollerith:~/null-arithmetic$ /home/mec/gcc-4.1-20051105/install/bin/gcc -c
null-arithmetic.cc
null-arithmetic.cc: In function 'int foo()':
null-arithmetic.cc:2: warning: converting to non-pointer type 'bool' from NULL
null-arithmetic.cc:3: warning: converting to non-pointer type 'bool' from NULL
null-arithmetic.cc:4: warning: NULL used in arithmetic
null-arithmetic.cc:5: warning: NULL used in arithmetic
null-arithmetic.cc:6: warning: NULL used in arithmetic
null-arithmetic.cc:7: warning: NULL used in arithmetic
--
Summary: unpleasant warning for "if (NULL)"
Product: gcc
Version: 4.0.2
Status: UNCONFIRMED
Severity: minor
Priority: P3
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: mec at google dot com
GCC build triplet: i686-pc-linux-gnu
GCC host triplet: i686-pc-linux-gnu
GCC target triplet: i686-pc-linux-gnu
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=24745
More information about the Gcc-bugs
mailing list