[clang] [bug 17456] cast diagnostic

Nathan Sidwell nathan at acm.org
Wed Dec 3 13:51:52 PST 2014


This patch addresses  17456, which is a desire for failed casts involving 
classes to give better diagnostic.  see http://llvm.org/bugs/show_bug.cgi?id=17456

Rather than a plain 'cannot cast' error, this patch changes things to:

1) for static cast from 'A *' to 'B *'  where T & S are classes, give
'static_cast from 'A *' to unrelated type 'B *' is not allowed'

2) where a cast fails and involves incomplete classes (directly or as a 
pointer), it also notes that the class is incomplete.  For instance:

17456.cc:6:10: error: static_cast from 'A *' to unrelated type 'B *' is not allowed
   return static_cast<B*>(arg);
          ^~~~~~~~~~~~~~~~~~~~
17456.cc:3:8: note: 'B' is incomplete
struct B;


The test suite already had applicable cases,  so this patch just adjusts those 
tests.

Perhaps the incomplete note should be broken out into a general utility 
function?  And perhaps unconditionally show the location of the class 
definition/declaration, as that's probably useful in figuring out how to fix the 
problem?

guidance welcome.

nathan
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 17456.patch
Type: text/x-patch
Size: 5740 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20141203/ffcd1d80/attachment.bin>


More information about the cfe-commits mailing list