From 17251338deebd6575ef2a9e2c99c3f976561dc93 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20L=C3=B3pez-Ib=C3=A1=C3=B1ez?= Date: Sat, 20 Feb 2010 21:32:06 +0000 Subject: re PR c++/35669 (NULL (__null) not considered different from 0 with C++) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 2010-02-20 Manuel López-Ibáñez 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 --- gcc/ChangeLog | 6 +++ gcc/c.opt | 4 ++ gcc/cp/ChangeLog | 7 ++++ gcc/cp/call.c | 14 ++++--- gcc/cp/cvt.c | 3 +- gcc/doc/invoke.texi | 19 +++++---- gcc/testsuite/ChangeLog | 9 +++++ gcc/testsuite/g++.dg/warn/Wconversion-null-2.C | 45 ++++++++++++++++++++++ gcc/testsuite/g++.dg/warn/Wconversion-null.C | 45 ++++++++++++++++++++++ gcc/testsuite/g++.dg/warn/Wconversion2.C | 3 +- gcc/testsuite/g++.old-deja/g++.other/null1.C | 45 ---------------------- libstdc++-v3/ChangeLog | 6 +++ .../testsuite/18_support/headers/cstddef/macros.cc | 1 + 13 files changed, 146 insertions(+), 61 deletions(-) create mode 100644 gcc/testsuite/g++.dg/warn/Wconversion-null-2.C create mode 100644 gcc/testsuite/g++.dg/warn/Wconversion-null.C delete mode 100644 gcc/testsuite/g++.old-deja/g++.other/null1.C diff --git a/gcc/ChangeLog b/gcc/ChangeLog index aa2d0fa..61e595e 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,5 +1,11 @@ 2010-02-20 Manuel López-Ibáñez + PR c++/35669 + * c.opt (Wconversion-null): New option. + * doc/invoke.texi (Wconversion-null): Document. + +2010-02-20 Manuel López-Ibáñez + * common.opt (Wlarger-than-): Add Undocumented. 2010-02-19 Mike Stump diff --git a/gcc/c.opt b/gcc/c.opt index e30aef3..82dee8d 100644 --- 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 diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 0f41c56..d71e2b4 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,10 @@ +2010-02-20 Manuel López-Ibáñez + + 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 PR c++/42837 diff --git a/gcc/cp/call.c b/gcc/cp/call.c index 5e66c62..7a6e104 100644 --- a/gcc/cp/call.c +++ b/gcc/cp/call.c @@ -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 % to pointer type for argument %P of %qD", - argnum, fn); + warning_at (input_location, OPT_Wconversion_null, + "converting % to pointer type for argument %P of %qD", + argnum, fn); } /* Perform the conversions in CONVS on the expression EXPR. FN and diff --git a/gcc/cp/cvt.c b/gcc/cp/cvt.c index 344816c..6fcb1f0 100644 --- a/gcc/cp/cvt.c +++ b/gcc/cp/cvt.c @@ -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); diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index a81cc99..a7abd01 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -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 diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 226c755..5555898 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,12 @@ +2010-02-20 Manuel López-Ibáñez + + 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 PR fortran/36932 diff --git a/gcc/testsuite/g++.dg/warn/Wconversion-null-2.C b/gcc/testsuite/g++.dg/warn/Wconversion-null-2.C new file mode 100644 index 0000000..d5c230f --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wconversion-null-2.C @@ -0,0 +1,45 @@ +// { dg-do link } +// { dg-options "" } + +#include + +void g(int) {} +void g(long) {} +extern void g(void*); + +template +void h() {} + +void k(int) {} + +template +void l(T); + +template <> +void l(int) {} + +template <> +void l(long) {} + +int main() +{ + int i = NULL; // { dg-warning "" } converting NULL to non-pointer type + float z = NULL; // { dg-warning "" } converting NULL to non-pointer type + int a[2]; + + i != NULL; // { dg-warning "" } NULL used in arithmetic + NULL != z; // { dg-warning "" } NULL used in arithmetic + k != NULL; // No warning: decay conversion + NULL != a; // Likewise. + -NULL; // { dg-warning "" } converting NULL to non-pointer type + +NULL; // { dg-warning "" } converting NULL to non-pointer type + ~NULL; // { dg-warning "" } converting NULL to non-pointer type + a[NULL] = 3; // { dg-warning "" } converting NULL to non-pointer-type + i = NULL; // { dg-warning "" } converting NULL to non-pointer type + z = NULL; // { dg-warning "" } converting NULL to non-pointer type + k(NULL); // { dg-warning "" } converting NULL to int + g(NULL); // { dg-warning "" } converting NULL to int + h(); // No warning: NULL bound to integer template parameter + l(NULL); // { dg-warning "" } converting NULL to int + NULL && NULL; // No warning: converting NULL to bool is OK +} diff --git a/gcc/testsuite/g++.dg/warn/Wconversion-null.C b/gcc/testsuite/g++.dg/warn/Wconversion-null.C new file mode 100644 index 0000000..205f5d2 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wconversion-null.C @@ -0,0 +1,45 @@ +// { dg-do link } +// { dg-options "-Wconversion -Wno-conversion-null -Wno-pointer-arith" } + +#include + +void g(int) {} +void g(long) {} +extern void g(void*); + +template +void h() {} + +void k(int) {} + +template +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(); // No warning: NULL bound to integer template parameter + l(NULL); // converting NULL to int + NULL && NULL; // No warning: converting NULL to bool is OK +} diff --git a/gcc/testsuite/g++.dg/warn/Wconversion2.C b/gcc/testsuite/g++.dg/warn/Wconversion2.C index a71b410..226dd85 100644 --- a/gcc/testsuite/g++.dg/warn/Wconversion2.C +++ b/gcc/testsuite/g++.dg/warn/Wconversion2.C @@ -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" } diff --git a/gcc/testsuite/g++.old-deja/g++.other/null1.C b/gcc/testsuite/g++.old-deja/g++.other/null1.C deleted file mode 100644 index 536f759..0000000 --- a/gcc/testsuite/g++.old-deja/g++.other/null1.C +++ /dev/null @@ -1,45 +0,0 @@ -// { dg-do link } -// { dg-options "-Wconversion" } - -#include - -void g(int) {} -void g(long) {} -extern void g(void*); - -template -void h() {} - -void k(int) {} - -template -void l(T); - -template <> -void l(int) {} - -template <> -void l(long) {} - -int main() -{ - int i = NULL; // { dg-warning "" } converting NULL to non-pointer type - float z = NULL; // { dg-warning "" } converting NULL to non-pointer type - int a[2]; - - i != NULL; // { dg-warning "" } NULL used in arithmetic - NULL != z; // { dg-warning "" } NULL used in arithmetic - k != NULL; // No warning: decay conversion - NULL != a; // Likewise. - -NULL; // { dg-warning "" } converting NULL to non-pointer type - +NULL; // { dg-warning "" } converting NULL to non-pointer type - ~NULL; // { dg-warning "" } converting NULL to non-pointer type - a[NULL] = 3; // { dg-warning "" } converting NULL to non-pointer-type - i = NULL; // { dg-warning "" } converting NULL to non-pointer type - z = NULL; // { dg-warning "" } converting NULL to non-pointer type - k(NULL); // { dg-warning "" } converting NULL to int - g(NULL); // { dg-warning "" } converting NULL to int - h(); // No warning: NULL bound to integer template parameter - l(NULL); // { dg-warning "" } converting NULL to int - NULL && NULL; // No warning: converting NULL to bool is OK -} diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index f89d8bc..cf7aa9e 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,9 @@ +2010-02-20 Manuel López-Ibáñez + + PR c++/35669 + * testsuite/18_support/headers/cstddef/macros.cc: Add + -Wno-conversion-null. + 2010-02-19 Paolo Carlini * include/tr1_impl/array (array): Add pointer and const_pointer diff --git a/libstdc++-v3/testsuite/18_support/headers/cstddef/macros.cc b/libstdc++-v3/testsuite/18_support/headers/cstddef/macros.cc index 1329e58..c17e86f 100644 --- a/libstdc++-v3/testsuite/18_support/headers/cstddef/macros.cc +++ b/libstdc++-v3/testsuite/18_support/headers/cstddef/macros.cc @@ -1,4 +1,5 @@ // { dg-do compile } +// { dg-options "-Wno-conversion-null" } // 2001-02-06 Benjamin Kosnik // Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2009 -- cgit v1.1