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]

[PATCH] [4of5] looking for feedback on Wcoercion warning (for stage1)


(The following patch implements part of the functionality of the
Wcoercion project as explained in
http://gcc.gnu.org/wiki/Wcoercion#Background ).

The following patch replaces some of the functionality of Wconversion
in g++ by using the code developed for Wcoercion project. In
particular, it replaces the testing of coercions from real to integer.
This is already tested by coercion_warning().

The proposed implementation has two advantages over the existing one:

* The code is shared by both C and C++ front ends in the function
"coercion_warning" which is called through the existing function
"convert_and_check". Thus, warning messages and checks are easily in
sync.

* The proposed implementation warns for int i = 1.1 but not for int i
= 1.0, while the previous code warned in both cases.

This is the 4th of a series of 5 patches. The previous patch can be
found at  http://gcc.gnu.org/ml/gcc-patches/2006-08/msg00280.html .

Bootstrapped and tested with --enable-languages=all for trunk revision
115951 on i686-pc-linux-gnu

:ADDPATCH c/c++:
diff -Ebpaur --unidirectional-new-file --exclude='*svn*' --exclude='#*' --exclude='*~' 3of3-coercion_warning/gcc/cp/call.c 4-gplusplus/gcc/cp/call.c
--- 3of3-coercion_warning/gcc/cp/call.c	2006-08-05 18:06:01.000000000 +0100
+++ 4-gplusplus/gcc/cp/call.c	2006-08-05 18:06:16.000000000 +0100
@@ -4255,11 +4255,10 @@ convert_like_real (conversion *convs, tr
       if (TREE_CODE (TREE_TYPE (expr)) == REAL_TYPE
 	  && TREE_CODE (t) == INTEGER_TYPE)
 	{
-	  if (fn)
-	    warning (OPT_Wconversion, "passing %qT for argument %P to %qD",
-		     TREE_TYPE (expr), argnum, fn);
-	  else
-	    warning (OPT_Wconversion, "converting to %qT from %qT", t, TREE_TYPE (expr));
+          convert_and_check (t, expr);
+          /* There is another call to convert_and_check below, we just
+             warn once.  */
+          issue_conversion_warnings = false;
 	}
     }
 
diff -Ebpaur --unidirectional-new-file --exclude='*svn*' --exclude='#*' --exclude='*~' 3of3-coercion_warning/gcc/testsuite/g++.dg/warn/conv2.C 4-gplusplus/gcc/testsuite/g++.dg/warn/conv2.C
--- 3of3-coercion_warning/gcc/testsuite/g++.dg/warn/conv2.C	2006-08-05 18:06:01.000000000 +0100
+++ 4-gplusplus/gcc/testsuite/g++.dg/warn/conv2.C	2006-08-05 18:06:16.000000000 +0100
@@ -1,4 +1,5 @@
 // PR c++/13932
-// { dg-options "-Wconversion" }
+// { dg-options "-Wcoercion" }
 
-int i = 1.; // { dg-warning "converting" }
+int i = 1.;
+int j = 1.1; // { dg-warning "coercion" }
diff -Ebpaur --unidirectional-new-file --exclude='*svn*' --exclude='#*' --exclude='*~' 3of3-coercion_warning/gcc/testsuite/g++.old-deja/g++.warn/impint2.C 4-gplusplus/gcc/testsuite/g++.old-deja/g++.warn/impint2.C
--- 3of3-coercion_warning/gcc/testsuite/g++.old-deja/g++.warn/impint2.C	2006-08-05 18:06:01.000000000 +0100
+++ 4-gplusplus/gcc/testsuite/g++.old-deja/g++.warn/impint2.C	2006-08-05 18:06:16.000000000 +0100
@@ -1,8 +1,9 @@
 // { dg-do assemble  }
-// { dg-options "-Wconversion" }
+// { dg-options "-Wcoercion" }
 
 // Copyright (C) 2000 Free Software Foundation, Inc.
 // Contributed by Nathan Sidwell 6 Mar 2000 <nathan@codesourcery.com>
+// Modified by Manuel Lopez-Ibanez 7 Jul 2006 <lopezibanez@gmail.com>
 
 // initialization to 'int' from to 'double' We expect consistent warnings
 // whenever a float is implicitly truncated to int, make sure references
diff -Ebpaur --unidirectional-new-file --exclude='*svn*' --exclude='#*' --exclude='*~' 3of3-coercion_warning/gcc/testsuite/g++.old-deja/g++.warn/impint.C 4-gplusplus/gcc/testsuite/g++.old-deja/g++.warn/impint.C
--- 3of3-coercion_warning/gcc/testsuite/g++.old-deja/g++.warn/impint.C	2006-08-05 18:06:01.000000000 +0100
+++ 4-gplusplus/gcc/testsuite/g++.old-deja/g++.warn/impint.C	2006-08-05 18:06:16.000000000 +0100
@@ -1,7 +1,9 @@
 // { dg-do assemble  }
-// { dg-options "-Wconversion" }
+// { dg-options "-Wcoercion" }
+
 // Copyright (C) 2000 Free Software Foundation, Inc.
 // Contributed by Nathan Sidwell 24 Feb 2000 <nathan@codesourcery.com>
+// Modified by Manuel Lopez-Ibanez 7 Jul 2006 <lopezibanez@gmail.com>
 
 // derived from a bug report by Johan Kuipers <j.kuipers@chello.nl>
 // initialization to 'int' from to 'double' We expect consistent warnings

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