+2018-05-30 Ville Voutilainen <ville.voutilainen@gmail.com>
+
+ Do not warn about zero-as-null when NULL is used.
+ * call.c (conversion_null_warnings): Check for pointer
+ types converted from zero constants.
+ (convert_like_real): Add a warning sentinel at the end.
+ * tree.c (maybe_warn_zero_as_null_pointer_constant): Also
+ check null_node_p.
+
2018-05-24 Jason Merrill <jason@redhat.com>
PR c++/85807 - ICE with call in template NSDMI.
}
/* Perform warnings about peculiar, but valid, conversions from/to NULL.
+ Also handle a subset of zero as null warnings.
EXPR is implicitly converted to type TOTYPE.
FN and ARGNUM are used for diagnostics. */
warning_at (input_location, OPT_Wconversion_null,
"converting %<false%> to pointer type %qT", totype);
}
+ /* Handle zero as null pointer warnings for cases other
+ than EQ_EXPR and NE_EXPR */
+ else if (null_ptr_cst_p (expr) &&
+ (TYPE_PTR_OR_PTRMEM_P (totype) || NULLPTR_TYPE_P (totype)))
+ {
+ source_location loc =
+ expansion_point_location_if_in_system_header (input_location);
+ maybe_warn_zero_as_null_pointer_constant (expr, loc);
+ }
}
/* We gave a diagnostic during a conversion. If this was in the second
&& !check_narrowing (totype, expr, complain))
return error_mark_node;
+ warning_sentinel w (warn_zero_as_null_pointer_constant);
if (issue_conversion_warnings)
expr = cp_convert_and_check (totype, expr, complain);
else
maybe_warn_zero_as_null_pointer_constant (tree expr, location_t loc)
{
if (c_inhibit_evaluation_warnings == 0
- && !NULLPTR_TYPE_P (TREE_TYPE (expr)))
+ && !null_node_p (expr) && !NULLPTR_TYPE_P (TREE_TYPE (expr)))
{
warning_at (loc, OPT_Wzero_as_null_pointer_constant,
"zero as null pointer constant");
--- /dev/null
+// { dg-options "-Wzero-as-null-pointer-constant" }
+// { dg-do compile { target c++11 } }
+
+#include <cstddef>
+
+void test01()
+{
+ char* x(NULL);
+ char* x2{NULL};
+ char* x3 = NULL;
+ char* x4(0); // { dg-warning "zero as null pointer" }
+ char* x5 = 0; // { dg-warning "zero as null pointer" }
+}