Compiling this test case: class C { public: int (*f())(); int bar(); }; int (*C::f())() { return C::bar; } produces this error message: foo3.cc: In member function `int (* C::f())()': foo3.cc:2: error: argument of type `int (C::)()' does not match `int (*)()' The error message is basically correct, but there is no `argument' here. The error message should refer to the return type instead. It might suffice to simply replace the word `argument' with the word `return'.
3.3.x gives: pr13657.cc: In member function `int (* C::f())()': pr13657.cc:2: error: no matches converting function `bar' to type `int (*)()' pr13657.cc:1: error: candidates are: int C::bar() I wound not call this a regression but I can confirm that the error message that 3.4 gives is a little confusing.
(In reply to comment #0) > The error message is basically correct, but there is no `argument' here. The > error message should refer to the return type instead. It might suffice to > simply replace the word `argument' with the word `return'. It is not that easy. The function that emits the error seems to be used for several things. However, at the point that the error is issued, I don't see any way to detect what we are actually doing. What do you think about this message? Will it work for any situation? error: ‘C::bar’ of type ‘int (C::)()’ does not match expected type ‘int (*)()’ The patch would be something like: - error ("argument of type %qT does not match %qT", TREE_TYPE (rhs), lhstype); + error ("%qE of type %qT does not match expected type %qT", rhs, TREE_TYPE(rhs), lhstype) Andrew? Gabriel? Ian? I can implement it and test it if you agree.
For this issue, would it make sense to keep on propagating the impl_conv_rhs argument passed by check_return_expr to convert_for_initialization - that is, ICR_RETURN - beyond convert_for_assignment, thus to can_convert_arg_bad -> implicit_conversion -> standard_conversion -> instantiate_type ? Or we want to aim for something more ad hoc in this case?
I think just making the error message more general makes sense here, something along the lines of "cannot convert..."
Ok, thanks, I'm doing that.
Author: paolo Date: Wed Oct 19 22:45:58 2011 New Revision: 180228 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=180228 Log: /cp 2011-10-19 Paolo Carlini <paolo.carlini@oracle.com> PR c++/13657 * class.c (instantiate_type): Fix error message. /testsuite 2011-10-19 Paolo Carlini <paolo.carlini@oracle.com> PR c++/13657 * g++.dg/parse/error42.C: New. * g++.old-deja/g++.other/ptrmem7.C: Tweak dg-errors. Added: trunk/gcc/testsuite/g++.dg/parse/error42.C Modified: trunk/gcc/cp/ChangeLog trunk/gcc/cp/class.c trunk/gcc/testsuite/ChangeLog trunk/gcc/testsuite/g++.old-deja/g++.other/ptrmem7.C
Fixed for 4.7.0.