This is the mail archive of the
mailing list for the GCC project.
Re: PR c++/5310 Weird warnings about using (int)NULL
- From: Mark Mitchell <mark at codesourcery dot com>
- To: Manuel López-Ibáñez <lopezibanez at gmail dot com>
- Cc: GCC Patches <gcc-patches at gcc dot gnu dot org>, Gabriel Dos Reis <gdr at integrable-solutions dot net>
- Date: Sun, 18 Nov 2007 12:38:49 -0800
- Subject: Re: PR c++/5310 Weird warnings about using (int)NULL
- References: <firstname.lastname@example.org>
Manuel López-Ibáñez wrote:
> 2007-11-15 Manuel Lopez-Ibanez <email@example.com>
> PR c++/5310
> * call.c (standard_conversion): When __null is cast to another
> integer type, save the target type in the conversion.
> (convert_like_real): If __null is cast to a different integer type,
> force conversion to that type.
> * g++.dg/warn/pr5310.C: New.
> * g++.dg/warn/pr33160.C: New.
I see Nathan has already approved this, but I have some questions:
+ if (same_type_p (from, to))
+ if (c_cast_p && expr && null_ptr_cst_p (expr))
+ conv->type = to;
+ return conv;
Why do we care about c_cast_p? Or, for that matter that this is a NULL
pointer? Couldn't we just do:
/* The types are the same. We use the destination type exactly so
that ... */
conv->type = to;
But, why do we need to change the type here, given that they are in fact
the same? The type of __null is not special; it is the fact that its
address is null_node that is the special characteristic. So, why do we
need the hunk in standard_conversion at all?
In convert_like_real, we should do the non-nullification magic after
calling decl_constant_value, as decl_constant_value itself might be
null_node for something like:
const int x = __null;
Then, if you want to check for null_node, using null_ptr_cst_p is not
the right predicate. That will consider just plain "0" as NULL (because
that it is a null pointer constant), but it doesn't have the problems
that we're having. Also, wouldn't these problems also apply to
enumeration target types?
So, I think the code should be something like:
expr = decl_constant_value (expr);
if (expr == null_node && INTEGRAL_TYPE_P (totype))
/* If __null has been converted to an integer type, we do not
want to warn about uses of EXPR as an integer, rather than
as a pointer. */
expr = build_integer_cst (totype, 0);
Again, I don't see any reason for the c_cast_p check.
(650) 331-3385 x713