Patchwork [C++,/,RFC] PR 48420

login
register
mail settings
Submitter Paolo Carlini
Date Nov. 4, 2011, 1:51 a.m.
Message ID <4EB34514.6060504@oracle.com>
Download mbox | patch
Permalink /patch/123555/
State New
Headers show

Comments

Paolo Carlini - Nov. 4, 2011, 1:51 a.m.
On 11/03/2011 05:06 PM, Jason Merrill wrote:
> I'd rather use maybe_constant_value here, but I think you don't need 
> to check the actual value at all; if we have decided that there is a 
> conversion from bool to pointer, it must be a null pointer constant, 
> and so false.
Ah! Thanks for the explanation, thus it seems even simpler than I 
thought yesterday.

I just booted and tested the below on x86_64-linux. Ok?

Thanks again,
Paolo.

///////////////
/cp
2011-11-04  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/48420
	* call.c (conversion_null_warnings): For 'false' to NULL pointer,
	just check that TREE_TYPE (expr) is a BOOLEAN_TYPE.

/testsuite
2011-11-04  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/48420
	* g++.dg/warn/Wconversion-null-3.C: New.
Jason Merrill - Nov. 4, 2011, 4:22 p.m.
OK.

Jason

Patch

Index: testsuite/g++.dg/warn/Wconversion-null-3.C
===================================================================
--- testsuite/g++.dg/warn/Wconversion-null-3.C	(revision 0)
+++ testsuite/g++.dg/warn/Wconversion-null-3.C	(revision 0)
@@ -0,0 +1,8 @@ 
+// PR c++/48420
+
+void foo(int* p);
+
+void bar() {
+  const bool kDebugMode = false;
+  foo(kDebugMode);   // { dg-warning "converting 'false'" }
+}
Index: cp/call.c
===================================================================
--- cp/call.c	(revision 180920)
+++ cp/call.c	(working copy)
@@ -5544,7 +5544,8 @@  conversion_null_warnings (tree totype, tree expr,
     }
 
   /* Issue warnings if "false" is converted to a NULL pointer */
-  else if (expr == boolean_false_node && TYPE_PTR_P (totype))
+  else if (TREE_CODE (TREE_TYPE (expr)) == BOOLEAN_TYPE
+	   && TYPE_PTR_P (totype))
     {
       if (fn)
 	warning_at (input_location, OPT_Wconversion_null,