[PATCH] Fix diagnostics for C-style cast to function type

Logan Chien tzuhsiang.chien at gmail.com
Sun Apr 13 09:17:27 PDT 2014


Hi Richard,

Thanks for your review.  Committed as r206133 with suggested change.
Thanks.

Logan


On Sat, Apr 12, 2014 at 3:45 AM, Richard Smith <richard at metafoo.co.uk>wrote:

> Sorry for the delay!
>
> +        // but the type cast should be considered as failure.
> +
> +        OverloadExpr* oe = OverloadExpr::find(SrcExpr.get()).Expression;
> +        Self.Diag(OpRange.getBegin(), diag::err_bad_cstyle_cast_overload)
> +          << oe->getName() << DestType << OpRange
> +          << oe->getQualifierLoc().getSourceRange();
> +        Self.NoteAllOverloadCandidates(SrcExpr.get());
>
> Some tiny typographical things here: no blank line between the comment and
> the code, put the * on the right not on the left, and 'oe' should be 'OE'.
> Otherwise, this looks good to me. Do you need someone to commit it for you?
>
>
> On Thu, Mar 27, 2014 at 9:51 AM, Logan Chien <tzuhsiang.chien at gmail.com>wrote:
>
>> Ping?
>>
>>
>> On Mon, Mar 17, 2014 at 11:59 PM, Logan Chien <tzuhsiang.chien at gmail.com>wrote:
>>
>>> Hi,
>>>
>>> It seems that if the C-style type cast is applied to the overloaded
>>> function and the destination type is function type, then Clang will crash
>>> with assertion failure.  For example,
>>>
>>>     void foo(int);
>>>     void foo(int, int);
>>>     void bar() {
>>>         typedef void (ft)(int);
>>>         ft p = (ft)foo;
>>>     }
>>>
>>> In this case, the overloaded function foo will be cast to a function
>>> type, which should be considered as an error.  But, unfortunately, since
>>> the function resolution is using canonical type, the matched function will
>>> be returned, and raise SEGV at lib/Sema/SemaCast.cpp:2101.
>>>
>>> This patch fixes this issue by removing the assertion and add some error
>>> diagnostics as the one in static_cast.  Please have a look.  Thanks.
>>>
>>> Logan
>>>
>>
>>
>> _______________________________________________
>> cfe-commits mailing list
>> cfe-commits at cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20140414/5e8669bf/attachment.html>


More information about the cfe-commits mailing list