Hi,
this issue seems pretty easy to deal with: submitter complains that we
warn for
void foo(int* p);
void bar() {
foo(false);
}
and we do *not* for:
void foo(int* p);
void bar() {
const bool kDebugMode = false;
foo(kDebugMode);
}
thus I tried using decl_constant_var_p / integral_constant_value and it
worked fine, as expected. However - I may be wrong - but I'm not seeing
*much* of this kind of idea around for diagnostic purposes, I'm afraid
I'm missing something. It is actually Ok?
Anyway, testsuite passes on x86_64-linux (bootstrap pending, important
because the W is on by default!)
Thanks,
Paolo.
//////////////////
/cp
2011-11-03 Paolo Carlini <paolo.carl...@oracle.com>
PR c++/48420
* call.c (conversion_null_warnings): For 'false' to NULL pointer,
look also inside constant VAR_DECLs.
/testsuite
2011-11-03 Paolo Carlini <paolo.carl...@oracle.com>
PR c++/48420
* g++.dg/warn/Wconversion-null-3.C: New.
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 180806)
+++ cp/call.c (working copy)
@@ -5542,17 +5542,22 @@ conversion_null_warnings (tree totype, tree expr,
warning_at (input_location, OPT_Wconversion_null,
"converting to non-pointer type %qT from NULL", totype);
}
+ else if (TYPE_PTR_P (totype))
+ {
+ if (decl_constant_var_p (expr))
+ expr = integral_constant_value (expr);
- /* Issue warnings if "false" is converted to a NULL pointer */
- else if (expr == boolean_false_node && TYPE_PTR_P (totype))
- {
- if (fn)
- warning_at (input_location, OPT_Wconversion_null,
- "converting %<false%> to pointer type for argument %P "
- "of %qD", argnum, fn);
- else
- warning_at (input_location, OPT_Wconversion_null,
- "converting %<false%> to pointer type %qT", totype);
+ /* Issue warnings if "false" is converted to a NULL pointer */
+ if (expr == boolean_false_node)
+ {
+ if (fn)
+ warning_at (input_location, OPT_Wconversion_null,
+ "converting %<false%> to pointer type for argument %P "
+ "of %qD", argnum, fn);
+ else
+ warning_at (input_location, OPT_Wconversion_null,
+ "converting %<false%> to pointer type %qT", totype);
+ }
}
}