[Bug c++/52806] "zero as null pointer constant" in C++98 mode

akim.demaille at gmail dot com gcc-bugzilla@gcc.gnu.org
Sat Mar 31 14:26:00 GMT 2012


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52806

--- Comment #4 from Akim Demaille <akim.demaille at gmail dot com> 2012-03-31 14:12:00 UTC ---
(In reply to comment #1)
> Oh well, changing this would be really trivial, but then people would have to
> globally switch-on -std=c++11 (which may not be otherwise appropriate) while
> working on removing (as much as possible) explicit zeros from C++98-era code. 

I don't think this comment makes sense: with what would you want them
to replace these 0, since nullptr is not available?

I'm having precisely this problem in Bison.  I want it to deliver code
which compiles without warning on the user side (so I cannot play
with Autoconf to check for nullptr support), so I use

# ifndef YY_NULL
#  if 201103L <= __cplusplus
#   define YY_NULL nullptr
#  else
#   define YY_NULL 0
#  endif
# endif

Unfortunately the user *will* have warnings if she passes the
warning flag but not -std=c++11.

This is even worse for C++03.

$ g++-mp-4.7 -std=c++03 -Wzero-as-null-pointer-constant /tmp/foo.cc
/tmp/foo.cc:1:11: warning: zero as null pointer constant
[-Wzero-as-null-pointer-constant]
/tmp/foo.cc:2:11: error: 'nullptr' was not declared in this scope

Or, be consistent with the flags that rejected when misused (such as
-Wmissing-prototypes that does not apply to C++) and reject
that warning when not in std=c++11.

The current status introduces non-killable warnings.



More information about the Gcc-bugs mailing list