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] (request for comments) Wcoercion in g++


The following patch replaces some of the functionality of Wconversion
in g++ by using the code developed for Wcoercion project. In
particular, it checks for coercions from real to integer.

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".

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

The patch must be applied after the ones given in
http://gcc.gnu.org/ml/gcc-patches/2006-07/msg00098.html

Bootstrapped and tested in trunk revision 115112

Comments and suggestions are very welcome.
diff -pEbaur --unidirectional-new-file --exclude='*svn*' --exclude='*~' pristine/gcc/cp/call.c wcoercion/gcc/cp/call.c
--- pristine/gcc/cp/call.c	2006-07-07 22:58:38.000000000 +0100
+++ wcoercion/gcc/cp/call.c	2006-07-09 19:21:13.000000000 +0100
@@ -4255,12 +4255,11 @@ 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 -pEbaur --unidirectional-new-file --exclude='*svn*' --exclude='*~' pristine/gcc/testsuite/g++.dg/warn/conv2.C wcoercion/gcc/testsuite/g++.dg/warn/conv2.C
--- pristine/gcc/testsuite/g++.dg/warn/conv2.C	2006-07-07 23:00:25.000000000 +0100
+++ wcoercion/gcc/testsuite/g++.dg/warn/conv2.C	2006-07-09 19:21:13.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 -pEbaur --unidirectional-new-file --exclude='*svn*' --exclude='*~' pristine/gcc/testsuite/g++.old-deja/g++.warn/impint2.C wcoercion/gcc/testsuite/g++.old-deja/g++.warn/impint2.C
--- pristine/gcc/testsuite/g++.old-deja/g++.warn/impint2.C	2006-07-07 23:22:57.000000000 +0100
+++ wcoercion/gcc/testsuite/g++.old-deja/g++.warn/impint2.C	2006-07-09 19:21:13.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 -pEbaur --unidirectional-new-file --exclude='*svn*' --exclude='*~' pristine/gcc/testsuite/g++.old-deja/g++.warn/impint.C wcoercion/gcc/testsuite/g++.old-deja/g++.warn/impint.C
--- pristine/gcc/testsuite/g++.old-deja/g++.warn/impint.C	2006-07-07 23:25:01.000000000 +0100
+++ wcoercion/gcc/testsuite/g++.old-deja/g++.warn/impint.C	2006-07-09 19:21:13.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]