[clang] Bug 17456 cast diagnostic

Nathan Sidwell nathan at acm.org
Fri Jan 23 12:37:54 PST 2015


Richard,
I think this is the remaining patch of mine waiting for review.

The original post is:
http://lists.cs.uiuc.edu/pipermail/cfe-commits/Week-of-Mon-20141201/119455.html 
but I duplicate the description here.  This updated patch fixes formatting, tabs 
and tweaks the error text, but otherwise is the same as the earlier posting.

The 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 hierarchy '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 hierarchy '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.

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


More information about the cfe-commits mailing list