mirror of
git://gcc.gnu.org/git/gcc.git
synced 2025-04-23 01:50:33 +08:00
typeck.c (build_binary_op_nodefault): Warn on use of NULL in arithmetic.
* typeck.c (build_binary_op_nodefault): Warn on use of NULL in arithmetic. * except.c (build_throw): Warn when NULL is thrown, even with -ansi. Use ansi_null_node, rather than integer_zero_node, in the thrown expression. From-SVN: r21863
This commit is contained in:
parent
893779cc02
commit
e0f9a8bc50
@ -1,5 +1,11 @@
|
||||
1998-08-19 Mark Mitchell <mark@markmitchell.com>
|
||||
|
||||
* typeck.c (build_binary_op_nodefault): Warn on use of NULL in
|
||||
arithmetic.
|
||||
* except.c (build_throw): Warn when NULL is thrown, even with
|
||||
-ansi. Use ansi_null_node, rather than integer_zero_node, in the
|
||||
thrown expression.
|
||||
|
||||
* cp-tree.h (ansi_null_node): New variable.
|
||||
* decl.c (ansi_null_node): New variable.
|
||||
(init_decl_processing): Initialize its type.
|
||||
@ -7,7 +13,7 @@
|
||||
for null_node in non-ANSI mode.
|
||||
* typeck.c (build_binary_op_nodefault): Use ansi_null_node in
|
||||
place of null_node to avoid spurious errors.
|
||||
|
||||
|
||||
1998-08-17 Mark Mitchell <mark@markmitchell.com>
|
||||
|
||||
* cp-tree.h (enter_scope_of): New function.
|
||||
|
@ -1277,10 +1277,10 @@ build_throw (e)
|
||||
if (processing_template_decl)
|
||||
return build_min (THROW_EXPR, void_type_node, e);
|
||||
|
||||
if (! flag_ansi && e == null_node)
|
||||
if (e == null_node)
|
||||
{
|
||||
cp_warning ("throwing NULL");
|
||||
e = integer_zero_node;
|
||||
cp_warning ("throwing NULL, which has integral, not pointer type");
|
||||
e = ansi_null_node;
|
||||
}
|
||||
|
||||
e = build1 (THROW_EXPR, void_type_node, e);
|
||||
|
@ -3248,23 +3248,21 @@ build_binary_op_nodefault (code, orig_op0, orig_op1, error_code)
|
||||
things like `7 != NULL' result in errors about comparisons
|
||||
between pointers and integers. So, here, we replace __null with
|
||||
an appropriate null pointer constant. */
|
||||
if (orig_op0 == null_node)
|
||||
orig_op0 = ansi_null_node;
|
||||
if (orig_op1 == null_node)
|
||||
orig_op1 = ansi_null_node;
|
||||
op0 = (orig_op0 == null_node) ? ansi_null_node : orig_op0;
|
||||
op1 = (orig_op1 == null_node) ? ansi_null_node : orig_op1;
|
||||
|
||||
/* Apply default conversions. */
|
||||
if (code == TRUTH_AND_EXPR || code == TRUTH_ANDIF_EXPR
|
||||
|| code == TRUTH_OR_EXPR || code == TRUTH_ORIF_EXPR
|
||||
|| code == TRUTH_XOR_EXPR)
|
||||
{
|
||||
op0 = decay_conversion (orig_op0);
|
||||
op1 = decay_conversion (orig_op1);
|
||||
op0 = decay_conversion (op0);
|
||||
op1 = decay_conversion (op1);
|
||||
}
|
||||
else
|
||||
{
|
||||
op0 = default_conversion (orig_op0);
|
||||
op1 = default_conversion (orig_op1);
|
||||
op0 = default_conversion (op0);
|
||||
op1 = default_conversion (op1);
|
||||
}
|
||||
|
||||
type0 = TREE_TYPE (op0);
|
||||
@ -3963,6 +3961,21 @@ build_binary_op_nodefault (code, orig_op0, orig_op1, error_code)
|
||||
return error_mark_node;
|
||||
}
|
||||
|
||||
if (/* If OP0 is NULL and OP1 is not a pointer, or vice versa. */
|
||||
(orig_op0 == null_node
|
||||
&& TREE_CODE (TREE_TYPE (orig_op1)) != POINTER_TYPE)
|
||||
/* Or vice versa. */
|
||||
|| (orig_op1 == null_node
|
||||
&& TREE_CODE (TREE_TYPE (orig_op0)) != POINTER_TYPE)
|
||||
/* Or, both are NULL and the operation was not a comparison. */
|
||||
|| (orig_op0 == null_node && orig_op1 == null_node
|
||||
&& code != EQ_EXPR && code != NE_EXPR))
|
||||
/* Some sort of arithmetic operation involving NULL was
|
||||
performed. Note that pointer-difference and pointer-addition
|
||||
have already been handled above, and so we don't end up here in
|
||||
that case. */
|
||||
cp_warning ("NULL used in arithmetic");
|
||||
|
||||
if (! converted)
|
||||
{
|
||||
if (TREE_TYPE (op0) != result_type)
|
||||
|
@ -7,6 +7,6 @@ void f()
|
||||
int i;
|
||||
float f;
|
||||
|
||||
i != NULL;
|
||||
f != NULL;
|
||||
i != NULL; // WARNING - NULL used in arithmetic
|
||||
f != NULL; // WARNING - NULL used in arithmetic
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user