This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: PR c++/5310 Weird warnings about using (int)NULL


On 18/11/2007, Mark Mitchell <mark@codesourcery.com> wrote:
> Manuel López-Ibáñez wrote:
>
> 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);
>

I implemented that. Bootstrapped and regression tested.

OK for mainline?

2007-11-15  Mark Mitchell  <mark@codsourcery.com>

 PR c++/5310
cp/
 * call.c (convert_like_real): Build a zero constant when __null is
converted to an integer type.

testsuite/
 * g++.dg/warn/pr5310.C: New.
 * g++.dg/warn/pr33160.C: New.
Index: gcc/testsuite/g++.dg/warn/pr5310.C
===================================================================
--- gcc/testsuite/g++.dg/warn/pr5310.C	(revision 0)
+++ gcc/testsuite/g++.dg/warn/pr5310.C	(revision 0)
@@ -0,0 +1,11 @@
+// PR 5310
+// { dg-do compile }
+// { dg-options "-pedantic -Wall -Wextra -Wpointer-arith -Wconversion" } 
+void foo (int);
+void foo (long);
+
+void bar()
+{
+   foo ((int)__null);
+   foo ((long)__null);
+}
Index: gcc/testsuite/g++.dg/warn/pr33160.C
===================================================================
--- gcc/testsuite/g++.dg/warn/pr33160.C	(revision 0)
+++ gcc/testsuite/g++.dg/warn/pr33160.C	(revision 0)
@@ -0,0 +1,12 @@
+// PR 33160
+// { dg-do compile }
+// { dg-options "-Wall -Wextra -Wpointer-arith -pedantic -Wconversion" }
+
+typedef int __attribute__((mode(pointer))) intptr_t;
+int foo(void)
+{
+ intptr_t t = 0;
+ if (t != ((intptr_t)__null)) t = 1;
+ return 0;
+}
+
Index: gcc/cp/call.c
===================================================================
--- gcc/cp/call.c	(revision 130174)
+++ gcc/cp/call.c	(working copy)
@@ -4420,7 +4420,14 @@
 	 about to bind it to a reference, in which case we need to
 	 leave it as an lvalue.  */
       if (inner >= 0)
-	expr = decl_constant_value (expr);
+        {   
+          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_int_cst (totype, 0);
+        }
       return expr;
     case ck_ambig:
       /* Call build_user_type_conversion again for the error.  */

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]