* init.c (perform_member_init): Check build_value_init return
value for error_mark_node.
+2011-04-29 Diego Novillo <dnovillo@google.com>
+ Le-Chun Wu <lcwu@google.com>
+
+ * call.c (conversion_null_warnings): Also handle assignments
+ when warning about NULL conversions.
+
+2011-04-29 Le-Chun Wu <lcwu@google.com>
+
+ * cp-tree.h (LOOKUP_EXPLICIT_TMPL_ARGS): Define.
+ * call.c (build_new_function_call): Set it for TEMPLATE_ID_EXPRs.
+ (build_over_call): Use it to determine whether to emit a NULL
+ warning for template function instantiations.
+ (build_new_method_call): Set LOOKUP_EXPLICIT_TMPL_ARGS if
+ EXPLICIT_TARGS is set.
+
2011-04-29 Nicola Pero <nicola.pero@meta-innovation.com>,
Mike Stump <mikestump@comcast.net>
result = error_mark_node;
}
else
- result = build_over_call (cand, LOOKUP_NORMAL, complain);
+ {
+ int flags = LOOKUP_NORMAL;
+ /* If fn is template_id_expr, the call has explicit template arguments
+ (e.g. func<int>(5)), communicate this info to build_over_call
+ through flags so that later we can use it to decide whether to warn
+ about peculiar null pointer conversion. */
+ if (TREE_CODE (fn) == TEMPLATE_ID_EXPR)
+ flags |= LOOKUP_EXPLICIT_TMPL_ARGS;
+ result = build_over_call (cand, flags, complain);
+ }
/* Free all the conversions we allocated. */
obstack_free (&conversion_obstack, p);
}
/* Issue warnings if "false" is converted to a NULL pointer */
- else if (expr == boolean_false_node && fn && POINTER_TYPE_P (t))
- warning_at (input_location, OPT_Wconversion_null,
- "converting %<false%> to pointer type for argument %P of %qD",
- argnum, fn);
+ else if (expr == boolean_false_node && POINTER_TYPE_P (t))
+ {
+ 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", t);
+ }
}
/* Perform the conversions in CONVS on the expression EXPR. FN and
{
tree type = TREE_VALUE (parm);
tree arg = VEC_index (tree, args, arg_index);
+ bool conversion_warning = true;
conv = convs[i];
+ /* If the argument is NULL and used to (implicitly) instantiate a
+ template function (and bind one of the template arguments to
+ the type of 'long int'), we don't want to warn about passing NULL
+ to non-pointer argument.
+ For example, if we have this template function:
+
+ template<typename T> void func(T x) {}
+
+ we want to warn (when -Wconversion is enabled) in this case:
+
+ void foo() {
+ func<int>(NULL);
+ }
+
+ but not in this case:
+
+ void foo() {
+ func(NULL);
+ }
+ */
+ if (arg == null_node
+ && DECL_TEMPLATE_INFO (fn)
+ && cand->template_decl
+ && !(flags & LOOKUP_EXPLICIT_TMPL_ARGS))
+ conversion_warning = false;
+
/* Warn about initializer_list deduction that isn't currently in the
working draft. */
if (cxx_dialect > cxx98
}
}
- val = convert_like_with_context (conv, arg, fn, i-is_method, complain);
+ val = convert_like_with_context (conv, arg, fn, i-is_method,
+ conversion_warning
+ ? complain
+ : complain & (~tf_warning));
val = convert_for_arg_passing (type, val);
if (val == error_mark_node)
if (DECL_VINDEX (fn) && ! (flags & LOOKUP_NONVIRTUAL)
&& resolves_to_fixed_type_p (instance, 0))
flags |= LOOKUP_NONVIRTUAL;
+ if (explicit_targs)
+ flags |= LOOKUP_EXPLICIT_TMPL_ARGS;
/* Now we know what function is being called. */
if (fn_p)
*fn_p = fn;
--- /dev/null
+// { dg-do compile }
+// { dg-options "-Wconversion-null" }
+
+#include <stddef.h>
+
+class Foo {
+ public:
+ template <typename T1, typename T2>
+ static void Compare(const T1& expected, const T2& actual) { }
+
+ template <typename T1, typename T2>
+ static void Compare(const T1& expected, T2* actual) { }
+
+};
+
+template<typename T1>
+class Foo2 {
+ public:
+ Foo2(int x);
+ template<typename T2> void Bar(T2 y);
+};
+
+template<typename T3> void func(T3 x) { }
+
+typedef Foo2<int> MyFooType;
+
+void func1(long int a) {
+ MyFooType *foo2 = new MyFooType(NULL); // { dg-warning "passing NULL to" }
+ foo2->Bar(a);
+ func(NULL);
+ func<int>(NULL); // { dg-warning "passing NULL to" }
+ func<int *>(NULL);
+}
+
+int x = 1;
+
+main()
+{
+ int *p = &x;
+
+ Foo::Compare(0, *p);
+ Foo::Compare<long int, int>(NULL, p); // { dg-warning "passing NULL to" }
+ Foo::Compare(NULL, p);
+ func1(NULL); // { dg-warning "passing NULL to" }
+}