]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR c++/35669 (NULL (__null) not considered different from 0 with C++)
authorManuel López-Ibáñez <manu@gcc.gnu.org>
Sat, 20 Feb 2010 21:32:06 +0000 (21:32 +0000)
committerManuel López-Ibáñez <manu@gcc.gnu.org>
Sat, 20 Feb 2010 21:32:06 +0000 (21:32 +0000)
2010-02-20  Manuel López-Ibáñez  <manu@gcc.gnu.org>

PR c++/35669
* c.opt (Wconversion-null): New option.
* doc/invoke.texi (Wconversion-null): Document.

cp/
* call.c (conversion_null_warnings): Replace -Wconversion with
-Wconversion-null.
* cvt.c (build_expr_type_conversion): Likewise.

testsuite/
* g++.dg/warn/Wconversion2.C: Replace -Wconversion with
-Wconversion-null.
* g++.dg/warn/Wconversion-null.C: New test.
* g++.old-deja/g++.other/null1.C: Move to...
* g++.dg/warn/Wconversion-null-2.C: ... here. Remove -Wconversion.

libstdc++-v3/
* testsuite/18_support/headers/cstddef/macros.cc: Add
-Wno-conversion-null.

From-SVN: r156928

12 files changed:
gcc/ChangeLog
gcc/c.opt
gcc/cp/ChangeLog
gcc/cp/call.c
gcc/cp/cvt.c
gcc/doc/invoke.texi
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/warn/Wconversion-null-2.C [moved from gcc/testsuite/g++.old-deja/g++.other/null1.C with 97% similarity]
gcc/testsuite/g++.dg/warn/Wconversion-null.C [new file with mode: 0644]
gcc/testsuite/g++.dg/warn/Wconversion2.C
libstdc++-v3/ChangeLog
libstdc++-v3/testsuite/18_support/headers/cstddef/macros.cc

index aa2d0fa4dbe4ee995f1227aed84654d8edfc9513..61e595e82d4d5b49fe50507c47ddb1cfb0dd4d26 100644 (file)
@@ -1,3 +1,9 @@
+2010-02-20  Manuel López-Ibáñez  <manu@gcc.gnu.org>
+
+       PR c++/35669
+       * c.opt (Wconversion-null): New option.
+       * doc/invoke.texi (Wconversion-null): Document.
+
 2010-02-20  Manuel López-Ibáñez  <manu@gcc.gnu.org>
 
        * common.opt (Wlarger-than-): Add Undocumented.
index e30aef3e699bee2609e634c7199fb99ce9d46624..82dee8d4f7930e81ef6be059e7249ab763341781 100644 (file)
--- a/gcc/c.opt
+++ b/gcc/c.opt
@@ -171,6 +171,10 @@ Wconversion
 C ObjC C++ ObjC++ Var(warn_conversion) Warning
 Warn for implicit type conversions that may change a value
 
+Wconversion-null
+C++ ObjC++ Var(warn_conversion_null) Init(1) Warning
+Warn for converting NULL from/to a non-pointer type
+
 Wsign-conversion
 C ObjC C++ ObjC++ Var(warn_sign_conversion) Init(-1)
 Warn for implicit type conversions between signed and unsigned integers
index 0f41c56aaa4438ecfdc657bc670dfb8b1ecc3348..d71e2b43c5739cd4c493ecc85614e99d95bb770d 100644 (file)
@@ -1,3 +1,10 @@
+2010-02-20  Manuel López-Ibáñez  <manu@gcc.gnu.org>
+
+       PR c++/35669
+       * call.c (conversion_null_warnings): Replace -Wconversion with
+       -Wconversion-null.
+       * cvt.c (build_expr_type_conversion): Likewise.
+
 2010-02-18  Jason Merrill  <jason@redhat.com>
 
        PR c++/42837
index 5e66c625295adf627d55eb77871d85ba69e3ecc0..7a6e1041dce362f039a1834ee0a1d6da7c176754 100644 (file)
@@ -4804,17 +4804,19 @@ conversion_null_warnings (tree totype, tree expr, tree fn, int argnum)
   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",
-                argnum, fn);
+       warning_at (input_location, OPT_Wconversion_null,
+                   "passing NULL to non-pointer argument %P of %qD",
+                   argnum, fn);
       else
-       warning (OPT_Wconversion, "converting to non-pointer type %qT from NULL", t);
+       warning_at (input_location, OPT_Wconversion_null,
+                   "converting to non-pointer type %qT from NULL", t);
     }
 
   /* Issue warnings if "false" is converted to a NULL pointer */
   else if (expr == boolean_false_node && fn && POINTER_TYPE_P (t))
-    warning (OPT_Wconversion,
-            "converting %<false%> to pointer type for argument %P of %qD",
-            argnum, fn);
+    warning_at (input_location, OPT_Wconversion_null,
+               "converting %<false%> to pointer type for argument %P of %qD",
+               argnum, fn);
 }
 
 /* Perform the conversions in CONVS on the expression EXPR.  FN and
index 344816ccd92037f5ea8f39d0cae80266e1b8b74d..6fcb1f0a19aa3b4eda4ade53374875246cdc17ff 100644 (file)
@@ -1141,7 +1141,8 @@ build_expr_type_conversion (int desires, tree expr, bool complain)
   if (expr == null_node
       && (desires & WANT_INT)
       && !(desires & WANT_NULL))
-    warning (OPT_Wconversion, "converting NULL to non-pointer type");
+    warning_at (input_location, OPT_Wconversion_null,
+               "converting NULL to non-pointer type");
 
   basetype = TREE_TYPE (expr);
 
index a81cc9932336a2e2fc643cb18cae928ce24bf661..a7abd01c940cacfd4439b3898c1768ced9604459 100644 (file)
@@ -194,7 +194,7 @@ in the following sections.
 -fno-threadsafe-statics -fuse-cxa-atexit  -fno-weak  -nostdinc++ @gol
 -fno-default-inline  -fvisibility-inlines-hidden @gol
 -fvisibility-ms-compat @gol
--Wabi  -Wctor-dtor-privacy @gol
+-Wabi  -Wconversion-null  -Wctor-dtor-privacy @gol
 -Wnon-virtual-dtor  -Wreorder @gol
 -Weffc++  -Wstrict-null-sentinel @gol
 -Wno-non-template-friend  -Wold-style-cast @gol
@@ -3837,14 +3837,19 @@ changed by the conversion like in @code{abs (2.0)}.  Warnings about
 conversions between signed and unsigned integers can be disabled by
 using @option{-Wno-sign-conversion}.
 
-For C++, also warn for conversions between @code{NULL} and non-pointer
-types; confusing overload resolution for user-defined conversions; and
-conversions that will never use a type conversion operator:
-conversions to @code{void}, the same type, a base class or a reference
-to them. Warnings about conversions between signed and unsigned
-integers are disabled by default in C++ unless
+For C++, also warn for confusing overload resolution for user-defined
+conversions; and conversions that will never use a type conversion
+operator: conversions to @code{void}, the same type, a base class or a
+reference to them. Warnings about conversions between signed and
+unsigned integers are disabled by default in C++ unless
 @option{-Wsign-conversion} is explicitly enabled.
 
+@item -Wno-conversion-null @r{(C++)}
+@opindex Wconversion-null
+@opindex Wno-conversion-null
+Do not warn for conversions between @code{NULL} and non-pointer
+types. @option{-Wconversion-null} is enabled by default.
+
 @item -Wempty-body
 @opindex Wempty-body
 @opindex Wno-empty-body
index 226c755fbb7108e222dcaec9e51100eb27413d0a..5555898d80f87db9d364d8b57d3504b5c0fad6bb 100644 (file)
@@ -1,3 +1,12 @@
+2010-02-20  Manuel López-Ibáñez  <manu@gcc.gnu.org>
+
+       PR c++/35669
+       * g++.dg/warn/Wconversion2.C: Replace -Wconversion with
+       -Wconversion-null.
+       * g++.dg/warn/Wconversion-null.C: New test.
+       * g++.old-deja/g++.other/null1.C: Move to...
+       * g++.dg/warn/Wconversion-null-2.C: ... here. Remove -Wconversion.
+
 2010-02-20  Paul Thomas  <pault@gcc.gnu.org>
 
        PR fortran/36932
similarity index 97%
rename from gcc/testsuite/g++.old-deja/g++.other/null1.C
rename to gcc/testsuite/g++.dg/warn/Wconversion-null-2.C
index 536f759e6a197fed3107d37be47f97659f50510f..d5c230f17833840c2e4d3d772898a28f72b5004c 100644 (file)
@@ -1,5 +1,5 @@
 // { dg-do link  }
-// { dg-options "-Wconversion" }
+// { dg-options "" }
 
 #include <cstddef>
 
diff --git a/gcc/testsuite/g++.dg/warn/Wconversion-null.C b/gcc/testsuite/g++.dg/warn/Wconversion-null.C
new file mode 100644 (file)
index 0000000..205f5d2
--- /dev/null
@@ -0,0 +1,45 @@
+// { dg-do link  }
+// { dg-options "-Wconversion -Wno-conversion-null -Wno-pointer-arith" }
+
+#include <cstddef>
+
+void g(int) {}
+void g(long) {}
+extern void g(void*);
+
+template <int I>
+void h() {}
+
+void k(int) {}
+
+template <class T>
+void l(T);
+
+template <>
+void l(int) {}
+
+template <>
+void l(long) {}
+
+int main()
+{
+  int i = NULL; //  converting NULL to non-pointer type
+  float z = NULL; //  converting NULL to non-pointer type
+  int a[2];
+
+  i != NULL; //  NULL used in arithmetic
+  NULL != z; //  NULL used in arithmetic
+  k != NULL; // No warning: decay conversion
+  NULL != a; // Likewise.
+  -NULL;     //  converting NULL to non-pointer type
+  +NULL;     //  converting NULL to non-pointer type
+  ~NULL;     //  converting NULL to non-pointer type
+  a[NULL] = 3; //  converting NULL to non-pointer-type
+  i = NULL;  //  converting NULL to non-pointer type
+  z = NULL;  //  converting NULL to non-pointer type
+  k(NULL);   //  converting NULL to int
+  g(NULL);   //  converting NULL to int
+  h<NULL>(); // No warning: NULL bound to integer template parameter
+  l(NULL);   //  converting NULL to int
+  NULL && NULL; // No warning: converting NULL to bool is OK
+}
index a71b410018c61d7ea361b02f8c91bef36a3bc50d..226dd852b760e3a020af926208e36857b4ba4580 100644 (file)
@@ -1,4 +1,3 @@
-// { dg-options "-Wconversion" }
-
+// { dg-options "-Wconversion-null" }
 void foo(const char *); 
 void bar() { foo(false); } // { dg-warning "pointer type for argument" }
index f89d8bc30c0f02ee9109be835d9df01a58abaa3f..cf7aa9e8d7c7e1fd7f3c200483356fc29b5826a1 100644 (file)
@@ -1,3 +1,9 @@
+2010-02-20  Manuel López-Ibáñez  <manu@gcc.gnu.org>
+
+       PR c++/35669
+       * testsuite/18_support/headers/cstddef/macros.cc: Add
+       -Wno-conversion-null.
+
 2010-02-19  Paolo Carlini  <paolo.carlini@oracle.com>
 
        * include/tr1_impl/array (array): Add pointer and const_pointer
index 1329e584e10edf991126d7da160c27e1d381bf3d..c17e86f5ec0be5cab886e42d5a464e01aac8d580 100644 (file)
@@ -1,4 +1,5 @@
 // { dg-do compile }
+// { dg-options "-Wno-conversion-null" }
 // 2001-02-06  Benjamin Kosnik  <bkoz@redhat.com>
 
 // Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2009