This borrows heavily in logic (and code) from the excellent diagnostics we he generate for overload resolution failure. We provide more tailored diagnostics and APIs to the error path in the initialization code. Currently there is still some common logic between them (CVR manipulation, etc) that should really be factored out, as well as plenty of ugliness (this is my first major attempt at diagnostics), so be merciful. ;]
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.
Here are some examples of resulting diagnostics:
% cat t.cc
class Derived;
class Base { };
Base* test1(Derived* d) { return d; }
void test2(Derived* d) {
Base* b = d;
(void)b;
}
% ./bin/clang -fsyntax-only t.cc
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; }
^
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;
^ ~
2 diagnostics generated.
% ./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 (*)(...)'
int (*pfe)(...) = &f; // expected-error{{cannot initialize a
variable of type 'int (*)(...)' with an rvalue of type '<overloaded
function type>'}}
^ ~
<snip rest>
improve_init_diags.patch
Description: Binary data
_______________________________________________ cfe-commits mailing list [email protected] http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
