[clang] Bug 17456 cast diagnostic

Richard Smith richard at metafoo.co.uk
Tue Jan 27 17:17:32 PST 2015


On Tue, Jan 27, 2015 at 3:35 PM, Nathan Sidwell <nathan at acm.org> wrote:

> On 01/23/15 16:49, Richard Smith wrote:
>
>
>> How about "static_cast from 'A *' to type 'B *' that is not related by
>> inheritance is not allowed"? As it stands, it sounds like you're
>> calling the type 'B *' a hierarchy. Also, consider:
>>
>
> Yeah, I was struggling with suitable  wording.  This version goes with:
>  ... from %1 to %2, which are unrelated by inheritance, is not allowed


I slightly prefer "are not related" over "are unrelated" (because we're
talking about the absence of a property, rather than a negative property
existing, especially in the case of an incomplete type).

 While here, please give err_bad_cxx_cast_unrelated a slightly more
>> specific name; [...]unrelated_class or similar?
>>
>
> Done.
>
>  I think we should only do this if we're casting to and from a class
>> type; I don't think it's useful to point out that T is an incomplete
>> type in:
>>
>
> Done.
>
>  Also, we should produce a similar "unrelated hierarchy" diagnostic and
>> "incomplete" note when casting to a reference to incomplete class type
>> or casting from an lvalue of incomplete class type.
>>
>
> Not disagreeing.  Can we handle this in a different patch?


Sure.


> Finally, trivial formatting things:
>>   * remove the space before the parens in the function calls above.
>>
>
> Done.  It's going to take a while to retrain my fingers.
>
>    * put the && on the previous line when it's used in a line continuation:
>>
>> +      if (SrcPointer->getPointeeType()->getAs<RecordType>()
>> +          && DestPointer->getPointeeType()->getAs<RecordType>())
>>
>
> Done.  (inconsistent with how << is formatted, but what the hey)
>
> ok?


+  if (auto Ptr = To->getAs<PointerType>())
+    {
+      To = Ptr->getPointeeType();

{ on previous line, and only 2 space indent, please.

LGTM modulo the above, thanks!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20150127/8d07d987/attachment.html>


More information about the cfe-commits mailing list