From: Dodji Seketeli Date: Thu, 23 Apr 2009 15:55:47 +0000 (+0000) Subject: re PR c++/38228 (ICE with invalid use of bound member function) X-Git-Tag: releases/gcc-4.3.4~211 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=82923a5ae35e4e859a439633bfc9883c45ed3e14;p=thirdparty%2Fgcc.git re PR c++/38228 (ICE with invalid use of bound member function) 2009-04-23 Dodji Seketeli gcc/cp/ChangeLog: 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; gcc/testsuite/ChangeLog: PR c++/38228 * g++.dg/expr/bound-mem-fun.C: New test. From-SVN: r146651 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 7e5eb2d78cb0..395196af05ea 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,15 @@ +2009-04-23 Dodji Seketeli + + 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 PR c++/39639 diff --git a/gcc/cp/call.c b/gcc/cp/call.c index 13713131d0b1..fb2420f2a596 100644 --- a/gcc/cp/call.c +++ b/gcc/cp/call.c @@ -3910,8 +3910,20 @@ build_new_op (enum tree_code code, int flags, tree arg1, tree arg2, tree arg3, 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; diff --git a/gcc/cp/cvt.c b/gcc/cp/cvt.c index a75036f53c11..7da8cc3cbf6d 100644 --- a/gcc/cp/cvt.c +++ b/gcc/cp/cvt.c @@ -740,8 +740,15 @@ ocp_convert (tree type, tree expr, int convtype, int flags) } 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; } diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 8cf6f410e64c..46866c030485 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -13035,6 +13035,13 @@ unify (tree tparms, tree targs, tree parm, tree arg, int strict) && !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; diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c index e8094b746845..10c3a022c3d8 100644 --- a/gcc/cp/typeck.c +++ b/gcc/cp/typeck.c @@ -1450,7 +1450,7 @@ cxx_sizeof_or_alignof_expr (tree e, enum tree_code op) 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; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index a9b3c604fc33..0a7cd962005a 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2009-04-23 Dodji Seketeli + + PR c++/38228 + * g++.dg/expr/bound-mem-fun.C: New test. + 2009-04-22 Dodji Seketeli PR c++/39639 diff --git a/gcc/testsuite/g++.dg/expr/bound-mem-fun.C b/gcc/testsuite/g++.dg/expr/bound-mem-fun.C new file mode 100644 index 000000000000..9e699b638e36 --- /dev/null +++ b/gcc/testsuite/g++.dg/expr/bound-mem-fun.C @@ -0,0 +1,18 @@ +// Contributed by Dodji Seketeli +// Origin PR c++/38228 +// { dg-do "compile" } + +struct A +{ + A (); + template A(T); +}; + +struct B +{ + int foo(); +}; + +A a = B().*(&B::foo); // { dg-error "invalid use of non-static member function" } + +