[cfe-commits] PATCH: Improve diagnostics for conversion failures during initialization

Chandler Carruth chandlerc at google.com
Sat Feb 27 03:43:32 PST 2010


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>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: improve_init_diags.patch
Type: application/octet-stream
Size: 9118 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20100227/468cdd34/attachment.obj>


More information about the cfe-commits mailing list