This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/35669] NULL (__null) not considered different from 0 with C++
- From: "truedfx at gentoo dot org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 23 Mar 2008 18:59:30 -0000
- Subject: [Bug c++/35669] NULL (__null) not considered different from 0 with C++
- References: <bug-35669-14453@http.gcc.gnu.org/bugzilla/>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
------- Comment #4 from truedfx at gentoo dot org 2008-03-23 18:59 -------
(In reply to comment #3)
> As for this PR, the warning from the C front-end seems to be mandated by the
> standard (I say this because using -pedantic-errors gives an error instead, so
> it is a pedwarn, it would be nice to know where in the C standard this appears,
> to add a comment to the code for future reference).
C allows NULL to be defined as 0 (or other integral constant expressions
evaluating to 0), or as such an expression cast to void *. (C99 7.17p3 &
6.3.2.2p3.) GCC defines NULL as ((void *) 0) in C mode. An implicit conversion
from ((void *) 0) to int is not allowed by either C or by C++. (C99 6.5.4p3.)
If GCC defined NULL as 0 in C mode, which would be a different but equally
legitimate definition, the code would have to be accepted.
> Perhaps the C++ standard does not mandate such warning.
The C++ standard also requires a diagnostic for an implicit conversion from
((void *) 0) to int. However, it does not allow ((void *) 0) as a null pointer
constant, and requires an expression of integral type. This means implicit
conversions from NULL to non-pointer types may legitimately be rejected in C,
but not in C++.
> If the C++ standard
> actually mandated the warning, this would be a bug.
It doesn't.
> Otherwise, whether this is
> worth warning or a nuisance is a matter of opinion.
True. So, is there any example where use of NULL / __null in a non-pointer
context is a good idea?
--
truedfx at gentoo dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |truedfx at gentoo dot org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35669