aboutsummaryrefslogtreecommitdiff
path: root/gcc/cp
diff options
context:
space:
mode:
authorManuel López-Ibáñez <manu@gcc.gnu.org>2007-01-30 22:29:11 +0000
committerManuel López-Ibáñez <manu@gcc.gnu.org>2007-01-30 22:29:11 +0000
commitb9edb4b11c99720e10625b41d37dc440bd468f2c (patch)
tree6ab5f599b4f4444b77112bd54a7ebdc103ca2f51 /gcc/cp
parent14734fc701357c82967954578c822f3ddede043f (diff)
downloadgcc-b9edb4b11c99720e10625b41d37dc440bd468f2c.zip
gcc-b9edb4b11c99720e10625b41d37dc440bd468f2c.tar.gz
gcc-b9edb4b11c99720e10625b41d37dc440bd468f2c.tar.bz2
re PR c++/24745 (unpleasant warning for "if (NULL)")
2007-01-30 Manuel Lopez-Ibanez <manu@gcc.gnu.org> PR c++/24745 * doc/invoke.texi (Wpointer-arith): Document warning. cp/ * typeck.c (build_binary_op): Fix logic for warning. Move warning to -Wpointer-arith. * call.c (convert_like_real): Don't warn when converting to boolean type. testsuite/ * g++.dg/warn/null4.C: New. From-SVN: r121361
Diffstat (limited to 'gcc/cp')
-rw-r--r--gcc/cp/ChangeLog8
-rw-r--r--gcc/cp/call.c2
-rw-r--r--gcc/cp/typeck.c32
3 files changed, 24 insertions, 18 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 0746d6a..ad008bf 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,11 @@
+2007-01-30 Manuel Lopez-Ibanez <manu@gcc.gnu.org>
+
+ PR c++/24745
+ * typeck.c (build_binary_op): Fix logic for warning. Move warning
+ to -Wpointer-arith.
+ * call.c (convert_like_real): Don't warn when converting to
+ boolean type.
+
2007-01-29 Manuel Lopez-Ibanez <manu@gcc.gnu.org>
* decl.c (pop_label): Replace warning with call to
diff --git a/gcc/cp/call.c b/gcc/cp/call.c
index 55ae284..ac29ecd 100644
--- a/gcc/cp/call.c
+++ b/gcc/cp/call.c
@@ -4250,7 +4250,7 @@ convert_like_real (conversion *convs, tree expr, tree fn, int argnum,
tree t = non_reference (totype);
/* Issue warnings about peculiar, but valid, uses of NULL. */
- if (ARITHMETIC_TYPE_P (t) && expr == null_node)
+ if (expr == null_node && TREE_CODE (t) != BOOLEAN_TYPE && ARITHMETIC_TYPE_P (t))
{
if (fn)
warning (OPT_Wconversion, "passing NULL to non-pointer argument %P of %qD",
diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c
index 709d25b..829b867 100644
--- a/gcc/cp/typeck.c
+++ b/gcc/cp/typeck.c
@@ -3828,30 +3828,28 @@ build_binary_op (enum tree_code code, tree orig_op0, tree orig_op1,
}
}
- /* If CONVERTED is zero, both args will be converted to type RESULT_TYPE.
- Then the expression will be built.
- It will be given type FINAL_TYPE if that is nonzero;
- otherwise, it will be given type RESULT_TYPE. */
-
/* Issue warnings about peculiar, but valid, uses of NULL. */
- if (/* It's reasonable to use pointer values as operands of &&
+ if ((orig_op0 == null_node || orig_op1 == null_node)
+ /* It's reasonable to use pointer values as operands of &&
and ||, so NULL is no exception. */
- !(code == TRUTH_ANDIF_EXPR || code == TRUTH_ORIF_EXPR)
- && (/* If OP0 is NULL and OP1 is not a pointer, or vice versa. */
- (orig_op0 == null_node
- && TREE_CODE (TREE_TYPE (op1)) != POINTER_TYPE)
- /* Or vice versa. */
- || (orig_op1 == null_node
- && TREE_CODE (TREE_TYPE (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)))
+ && code != TRUTH_ANDIF_EXPR && code != TRUTH_ORIF_EXPR
+ && ( /* Both are NULL (or 0) and the operation was not a comparison. */
+ (null_ptr_cst_p (orig_op0) && null_ptr_cst_p (orig_op1)
+ && code != EQ_EXPR && code != NE_EXPR)
+ /* Or if one of OP0 or OP1 is neither a pointer nor NULL. */
+ || (!null_ptr_cst_p (orig_op0) && TREE_CODE (TREE_TYPE (op0)) != POINTER_TYPE)
+ || (!null_ptr_cst_p (orig_op1) && TREE_CODE (TREE_TYPE (op1)) != POINTER_TYPE)))
/* 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. */
- warning (0, "NULL used in arithmetic");
+ warning (OPT_Wpointer_arith, "NULL used in arithmetic");
+
+ /* If CONVERTED is zero, both args will be converted to type RESULT_TYPE.
+ Then the expression will be built.
+ It will be given type FINAL_TYPE if that is nonzero;
+ otherwise, it will be given type RESULT_TYPE. */
if (! converted)
{
if (TREE_TYPE (op0) != result_type)