[cfe-commits] PATCH: Improve diagnostics for conversion failures during initialization
John McCall
rjmccall at apple.com
Sat Feb 27 14:01:09 PST 2010
On Feb 27, 2010, at 3:43 AM, Chandler Carruth wrote:
> I've not finished updating all the tests to match the new format, but
> I've fixed the crashers. I really want feedback on whether these
> diagnostics are useful, do too much or too little, and wording or
> phrasing suggestions. In particular, Jeff already raised concerns
> about the incomplete type diagnostic (which motivated this cleanup).
> I've toned it down considerably based on his feedback, but he also
> mentioned that we might issue different diagnostics for a pointer type
> where we *know* that it must be an inheritance relationship if not
> exactly which one... Not sure how much i like this, but it's an
> interesting idea.
I haven't looked at the patch yet, but some comments about the diagnostics. In general, that's a lot of text. The overload-resolution diagnostics have to bend over backwards to establish context because they have to put the caret on the candidate's declaration. That's not true here; the caret and source ranges should make it perfectly clear that we're talking about a return value or a variable initializer. That means you can cut a *lot* of unnecessary verbiage out of the diagnostics.
> t.cc:3:34: error: cannot initialize the return object with an lvalue
> pointing to an incomplete type 'class Derived': cannot check
> conversion to a pointer to 'class Base' without a complete type
> Base* test1(Derived* d) { return d; }
"can't convert pointer to incomplete type 'class Derived' to 'class Base*'"
I think this is clear enough without calling out the fact that it has to be an inheritance relationship.
> t.cc:5:9: error: cannot initialize the variable 'b' with an lvalue
> pointing to an incomplete type 'class Derived': cannot check
> conversion to a pointer to 'class Base' without a complete type
> Base* b = d;
> ^ ~
Since you can let the caret establish context, you can re-use the same diagnostic here: "can't convert pointer to incomplete type 'class Derived' to 'class Base*'"
> % ./bin/clang -fsyntax-only .../test/SemaCXX/addr-of-overloaded-function.cpp
> .../test/SemaCXX/addr-of-overloaded-function.cpp:12:7: error: cannot
> initialize the variable 'pfe': no overload of the function 'f' matches
> 'int (*)(...)'
This is pretty good.
John.
More information about the cfe-commits
mailing list