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]

Re: [PATCH] [COMMITTED] Add warning about false being implicitly converted to NULL in parameter passing


On Thursday, 15. March 2007, Manuel López-Ibáñez wrote:

> Is this only important when passing values as function arguments or
> should it work also for assignments and other implicit conversions?

> For example, int *p = false; and such.

I've explicitely disabled the warning for this case because the original 
intention was to detect the wrong overload being taken due to an implicit 
false->pointer conversion. 

I've tested the warning and couldn't find a real issue with it in real code 
for assignments, so I think it is fine to omit that case. I don't have a 
strong feeling against it, so if its requested for consistency reasons I'll 
supply a patch + testcase. 

> Also, again I think that both warnings cannot be given at the same
> time, so using else-if would be better. If you agree I can fix this
> when re-building my Wconversion patch.

hmm, I would have hoped that jump threading figures that out all by itself. 
But before I have to proof that, how about the patch below?

So far not tested in anyway. 


--- cp/call.c   (revision 122955)
+++ cp/call.c   (working copy)
@@ -4262,9 +4262,13 @@ convert_conversion_warnings (tree totype
       else
        warning (OPT_Wconversion, "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);
   /* Warn about assigning a floating-point type to an integer type.  */
-  if (TREE_CODE (TREE_TYPE (expr)) == REAL_TYPE
+  else if (TREE_CODE (TREE_TYPE (expr)) == REAL_TYPE
       && TREE_CODE (t) == INTEGER_TYPE)
     {
       if (fn)
@@ -4273,12 +4277,6 @@ convert_conversion_warnings (tree totype
       else
        warning (OPT_Wconversion, "converting to %qT from %qT", t, TREE_TYPE 
(expr));
     }
-
-  /* Issue warnings if "false" is converted to a NULL pointer */
-  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);
 }

 /* Perform the conversions in CONVS on the expression EXPR.  FN and


Dirk


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