+2009-04-23 Dodji Seketeli <dodji@redhat.com>
+
+ PR c++/38228
+ * pt.c (unify): Do not allow the result of a template argument
+ deduction to be a METHOD_TYPE.
+ * cvt.c (cp_convert): Report a meaningful error for non-valid use
+ of pointer to member functions during conversions.
+ * call.c (build_new_op): Report a meaningful error for non-valid
+ use of pointer to member functions in binary expressions.
+ * typeck.c (invalid_nonstatic_memfn_p): Do not crash when EXPR is
+ NULL;
+
2009-04-22 Dodji Seketeli <dodji@redhat.com>
PR c++/39639
default:
if (flags & LOOKUP_COMPLAIN)
{
- op_error (code, code2, arg1, arg2, arg3, "no match");
- print_z_candidates (candidates);
+ /* If one of the arguments of the operator represents
+ an invalid use of member function pointer, try to report
+ a meaningful error ... */
+ if (invalid_nonstatic_memfn_p (arg1)
+ || invalid_nonstatic_memfn_p (arg2)
+ || invalid_nonstatic_memfn_p (arg3))
+ /* We displayed the error message. */;
+ else
+ {
+ /* ... Otherwise, report the more generic
+ "no matching operator found" error */
+ op_error (code, code2, arg1, arg2, arg3, "no match");
+ print_z_candidates (candidates);
+ }
}
result = error_mark_node;
break;
}
if (flags & LOOKUP_COMPLAIN)
- error ("conversion from %qT to non-scalar type %qT requested",
- TREE_TYPE (expr), type);
+ {
+ /* If the conversion failed and expr was an invalid use of pointer to
+ member function, try to report a meaningful error. */
+ if (invalid_nonstatic_memfn_p (expr))
+ /* We displayed the error message. */;
+ else
+ error ("conversion from %qT to non-scalar type %qT requested",
+ TREE_TYPE (expr), type);
+ }
return error_mark_node;
}
&& !template_parameter_pack_p (parm))
return 1;
+ /* If the argument deduction results is a METHOD_TYPE,
+ then there is a problem.
+ METHOD_TYPE doesn't map to any real C++ type the result of
+ the deduction can not be of that type. */
+ if (TREE_CODE (arg) == METHOD_TYPE)
+ return 1;
+
TREE_VEC_ELT (INNERMOST_TEMPLATE_ARGS (targs), idx) = arg;
return 0;
bool
invalid_nonstatic_memfn_p (const_tree expr)
{
- if (TREE_CODE (TREE_TYPE (expr)) == METHOD_TYPE)
+ if (expr && TREE_CODE (TREE_TYPE (expr)) == METHOD_TYPE)
{
error ("invalid use of non-static member function");
return true;
+2009-04-23 Dodji Seketeli <dodji@redhat.com>
+
+ PR c++/38228
+ * g++.dg/expr/bound-mem-fun.C: New test.
+
2009-04-22 Dodji Seketeli <dodji@redhat.com>
PR c++/39639
--- /dev/null
+// Contributed by Dodji Seketeli <dodji@redhat.com>
+// Origin PR c++/38228
+// { dg-do "compile" }
+
+struct A
+{
+ A ();
+ template<typename T> A(T);
+};
+
+struct B
+{
+ int foo();
+};
+
+A a = B().*(&B::foo); // { dg-error "invalid use of non-static member function" }
+
+