Bug 13657 - Error message incorrectly describes return type as argument type
Summary: Error message incorrectly describes return type as argument type
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 3.4.0
: P2 minor
Target Milestone: 4.7.0
Assignee: Gabriel Dos Reis
URL:
Keywords: diagnostic
Depends on:
Blocks:
 
Reported: 2004-01-12 16:35 UTC by Ian Lance Taylor
Modified: 2011-10-19 22:47 UTC (History)
4 users (show)

See Also:
Host: i686-pc-linux-gnu
Target: i686-pc-linux-gnu
Build: i686-pc-linux-gnu
Known to work:
Known to fail:
Last reconfirmed: 2006-02-26 19:21:50


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Ian Lance Taylor 2004-01-12 16:35:47 UTC
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'.
Comment 1 Andrew Pinski 2004-01-12 17:43:57 UTC
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.
Comment 2 Manuel López-Ibáñez 2007-01-26 23:47:49 UTC
(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.


Comment 3 Paolo Carlini 2011-10-19 18:10:53 UTC
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?
Comment 4 Jason Merrill 2011-10-19 20:52:01 UTC
I think just making the error message more general makes sense here, something along the lines of "cannot convert..."
Comment 5 Paolo Carlini 2011-10-19 22:06:56 UTC
Ok, thanks, I'm doing that.
Comment 6 paolo@gcc.gnu.org 2011-10-19 22:46:01 UTC
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
Comment 7 Paolo Carlini 2011-10-19 22:47:28 UTC
Fixed for 4.7.0.