Bug 24746 - unpleasant warning for "if (NULL)"
Summary: unpleasant warning for "if (NULL)"
Status: RESOLVED DUPLICATE of bug 24745
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.0.2
: P3 minor
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-11-08 23:27 UTC by Michael Elizabeth Chastain
Modified: 2005-11-08 23:40 UTC (History)
2 users (show)

See Also:
Host: i686-pc-linux-gnu
Target: i686-pc-linux-gnu
Build: i686-pc-linux-gnu
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Michael Elizabeth Chastain 2005-11-08 23:27:56 UTC
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
Comment 1 Andrew Pinski 2005-11-08 23:40:46 UTC

*** This bug has been marked as a duplicate of 24745 ***