On 29 May 2018 at 23:43, Ville Voutilainen <ville.voutilai...@gmail.com> wrote: > Another round. The other occurrence of > maybe_warn_zero_as_null_pointer_constant > in typeck.c seems superfluous. The one in cvt.c seems necessary for > cpp0x/Wzero-as-null* tests. It seems like cp_build_binary_op is far more > suited > to check the EQ_EXPR/NE_EXPR cases than conversion_null_warnings is. > > Tested manually on Linux-x64, running full suite on Linux-PPC64. Ok for trunk? > > 2018-05-29 Ville Voutilainen <ville.voutilai...@gmail.com> > > gcc/cp/ > > Do not warn about zero-as-null when NULL is used. > * typeck.c (cp_build_binary_op): Diagnose zero as null here.. > * call.c (conversion_null_warnings): ..and here.. > * cvt.c (cp_convert_to_pointer): ..not here. > > testsuite/ > > Do not warn about zero-as-null when NULL is used. > * g++.dg/warn/Wzero-as-null-pointer-constant-7.C: New.
If we want, we can fine-tune conversion_null_warnings to not bother with the source location if we don't call maybe_warn, thus.
diff --git a/gcc/cp/call.c b/gcc/cp/call.c index 5890b73..c7c9741 100644 --- a/gcc/cp/call.c +++ b/gcc/cp/call.c @@ -6556,12 +6556,14 @@ conversion_null_warnings (tree totype, tree expr, tree fn, int argnum) than EQ_EXPR and NE_EXPR */ else if (!null_node_p (expr)) { - source_location loc = - expansion_point_location_if_in_system_header (input_location); if (null_ptr_cst_p (expr) && (TYPE_PTRMEMFUNC_P (totype) || TYPE_PTRDATAMEM_P (totype) || TYPE_PTR_P (totype))) - maybe_warn_zero_as_null_pointer_constant (expr, loc); + { + source_location loc = + expansion_point_location_if_in_system_header (input_location); + maybe_warn_zero_as_null_pointer_constant (expr, loc); + } } }