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] Add warning about false being implicitly converted to NULL in parameter passing


Hi, 

Patch below was bootstrapped and regtested on i686-suse-linux.


2007-03-11  Dirk Mueller  <dmueller@suse.de>

        PR c++/30860
        * call.c (convert_like_real): Add conversion warning
        about false being converted to NULL in argument passing.

        * g++.dg/warn/Wconversion2.C: New testcase.

--- cp/call.c
+++ cp/call.c
@@ -4320,6 +4320,13 @@ convert_like_real (conversion *convs, tr
 	  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);
+
     }
 
   switch (convs->kind)
--- testsuite/g++.dg/warn/Wconversion2.C
+++ testsuite/g++.dg/warn/Wconversion2.C
@@ -0,0 +1,4 @@
+// { dg-options "-Wconversion" }
+
+void foo(const char *); 
+void bar() { foo(false); } // { dg-warning "pointer type argument" }


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