User account creation filtered due to spam.

Bug 49117 - 4.5 -> 4.6: user-unfriendly change in "invalid conversion" error message
Summary: 4.5 -> 4.6: user-unfriendly change in "invalid conversion" error message
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.7.0
: P3 normal
Target Milestone: 4.6.1
Assignee: Jason Merrill
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-05-22 23:32 UTC by Nathan Ridge
Modified: 2011-06-15 03:54 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Nathan Ridge 2011-05-22 23:32:53 UTC
Consider the following fragment of invalid code:
 
struct A
{
    struct B {};
 
    int g();
 
    B f() { return g(); }
};
 
GCC 4.5's error message is "error: conversion from 'int' to non-scalar type 'A::B' requested".
 
GCC 4.6's error message is "error: could not convert 'A::g()' to 'A::B'".
 
The 4.6 error message no longer mentions the actual type, int, that 
cannot be converted to the declared return type, insteading mentioning 
the expression yielding that type, A::g().
 
I think 4.5's error message is more useful because you can see from it 
exactly what conversion (int to A::B) is failing. With 4.6's error message, 
to find out why the conversion is failing you now have to look up the 
return value of A::g() in your code.
 
The difference becomes more pronounced with more complex examples.
For example, for the code in PR 49003,
 
GCC 4.5: "error: conversion from 'vector::const_iterator' to non-scalar type 'vector::iterator' requested"
 
GCC 4.6: "error: could not convert '((const block*)this)->block::v.vector::begin()' to 'vector::iterator'"
 
Quite clearly, the 4.5 error message is better.
 
Having said that, I think the phrasing of the 4.6 error is better.

I think for 4.7, the error message should keep the 4.6 phrasing, but go back to the 4.5 way of mentioning the type being converted from.

For example:
 
error: could not convert 'int' to 'A::B'".

or:

error: could not convert 'vector::const_iterator' to 'vector::iterator'
Comment 1 Jason Merrill 2011-06-14 18:16:08 UTC
Author: jason
Date: Tue Jun 14 18:16:06 2011
New Revision: 175044

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=175044
Log:
	PR c++/49117
	* call.c (perform_implicit_conversion_flags): Print source type as
	well as expression.

Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/call.c
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/g++.dg/other/error23.C
    trunk/gcc/testsuite/g++.dg/other/error32.C
Comment 2 Jason Merrill 2011-06-14 22:13:39 UTC
Author: jason
Date: Tue Jun 14 22:13:36 2011
New Revision: 175060

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=175060
Log:
	PR c++/49117
	* call.c (perform_implicit_conversion_flags): Print source type as
	well as expression.

Modified:
    branches/gcc-4_6-branch/gcc/cp/ChangeLog
    branches/gcc-4_6-branch/gcc/cp/call.c
    branches/gcc-4_6-branch/gcc/testsuite/ChangeLog
    branches/gcc-4_6-branch/gcc/testsuite/g++.dg/other/error23.C
    branches/gcc-4_6-branch/gcc/testsuite/g++.dg/other/error32.C
Comment 3 Jason Merrill 2011-06-15 03:54:34 UTC
Fixed for 4.6.1.