[cfe-commits] [PATCH] Implicit fall-through between switch labels

Alexander Kornienko alexfh at google.com
Thu Apr 26 05:42:02 PDT 2012


Hi Chandler,

On Thu, Apr 26, 2012 at 1:02 AM, Chandler Carruth <chandlerc at google.com>wrote:

>
>> test.cpp:16:5: note: insert [[fallthrough]]; to silence this warning
>> [-Wimplicit-fallthrough]
>>
>
> s/to silence this warning/to annotate the fall-through as intentional/ ?
>
I found it quite common in clang to use "to silence this warning" wording
in fix-it hints. As for me, it seems to be a good idea to have a common
wording for fix-it hints which leave semantic as is and just serve to shut
up the relevant diagnostic message. Or you see a reason to have a specific
message in this particular case?


>  * added specific diagnostic message for unreachable fall-through
>> annotation, e.g. this code:
>>
>> switch(x) {
>> case 1:
>>   break;
>>   [[fallthrough]];
>> case 2:
>> ...
>>
>> will produce a similar warning:
>> test.cpp:12:7: warning: fallthrough annotation in unreachable code
>> [-Wimplicit-fallthrough]
>>       [[fallthrough]];
>>       ^
>>
>
> Idea for a future iteration: add a note that points to the break here, at
> least in the easy cases. We should be able to find the terminator of the
> CFG block which precedes this somehow.
>
The whole point is that CFG block containing break statement doesn't
precede a block with a code just after the break.
BTW, current logic detects only trivially unreachable code, but if a part
of unreachable code contains branches/loops/etc, so it will treat it as a
fall-through (either annotated or not).

-- 
Best regards,
Alexander Kornienko
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20120426/ce24952c/attachment.html>


More information about the cfe-commits mailing list