re PR c++/5310 (Weird warnings about using (int)NULL)
authorMark Mitchell <mark@codesourcery.com>
Fri, 23 Nov 2007 19:15:09 +0000 (19:15 +0000)
committerManuel López-Ibáñez <manu@gcc.gnu.org>
Fri, 23 Nov 2007 19:15:09 +0000 (19:15 +0000)
2007-11-23  Mark Mitchell  <mark@codesourcery.com>
    Manuel Lopez-Ibanez  <manu@gcc.gnu.org>

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

Co-Authored-By: Manuel López-Ibáñez <manu@gcc.gnu.org>
From-SVN: r130381

gcc/cp/ChangeLog
gcc/cp/call.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/warn/pr33160.C [new file with mode: 0644]
gcc/testsuite/g++.dg/warn/pr5310.C [new file with mode: 0644]

index 48119fb0f29c0e1fa6a329ca74862fa021f61e6b..0aff9b197cc1db19361d59ad98f3c0ed98377458 100644 (file)
@@ -1,3 +1,10 @@
+2007-11-23  Mark Mitchell  <mark@codesourcery.com>
+           Manuel Lopez-Ibanez  <manu@gcc.gnu.org>
+       
+       PR c++/5310
+       * call.c (convert_like_real): Build a zero constant when __null is
+       converted to an integer type.
+       
 2007-11-22  Jakub Jelinek  <jakub@redhat.com>
 
        PR c++/34094
index ecb8858b124fd7a4d5435d7bddfd66fb3a6986f1..d240b85b03a7c1ca8e8009faae3b508776957194 100644 (file)
@@ -4420,7 +4420,14 @@ convert_like_real (conversion *convs, tree expr, tree fn, int argnum,
         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 9f893c3909640bfbd200c1db995b8f643759fecd..5e5578d8867df06f99701d1a4724d031dc167f4c 100644 (file)
@@ -1,3 +1,10 @@
+2007-11-23  Mark Mitchell  <mark@codesourcery.com>
+           Manuel Lopez-Ibanez  <manu@gcc.gnu.org>
+       
+       PR c++/5310
+       * g++.dg/warn/pr5310.C: New.
+       * g++.dg/warn/pr33160.C: New.
+       
 2007-11-23  Richard Guenther  <rguenther@suse.de>
        Michael Matz  <matz@suse.de>
 
diff --git a/gcc/testsuite/g++.dg/warn/pr33160.C b/gcc/testsuite/g++.dg/warn/pr33160.C
new file mode 100644 (file)
index 0000000..e463e2d
--- /dev/null
@@ -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;
+}
+
diff --git a/gcc/testsuite/g++.dg/warn/pr5310.C b/gcc/testsuite/g++.dg/warn/pr5310.C
new file mode 100644 (file)
index 0000000..48a6006
--- /dev/null
@@ -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);
+}