concurrencykit / ck

Concurrency primitives, safe memory reclamation mechanisms and non-blocking (including lock-free) data structures designed to aid in the research, design and implementation of high performance concurrent systems developed in C99+.
http://concurrencykit.org/
Other
2.35k stars 312 forks source link

Quiet implicit fallthrough compiler warnings. #109

Closed akopytov closed 6 years ago

akopytov commented 6 years ago

Annotate fall through cases in switch statements where that behavior is desirable to quiet compiler warnings with the -Wimplicit-fallthrough flag. The annotation format used is supported by both GCC and Clang.

Fixes #108.

cognet commented 6 years ago

Thanks a lot for taking care of this ! This is getting really annoying. But surely adding them at the beginning of switch is useless ?

akopytov commented 6 years ago

Clang supports /* All fallthrough */ annotations that can be used before a switch. Unfortunately that form is not (yet?) supported by GCC. I checked with gcc (Ubuntu 7.2.0-8ubuntu3) 7.2.0 from Ubuntu Artful.

cognet commented 6 years ago

I understand, but there :

 switch(len & 3)  {  + / fall through / I certainly hope this is not needed there, before any "case" :)

akopytov commented 6 years ago

Hm, not sure I understand that comment. I'm quoting the GCC manual:

The comment needs to be followed after optional whitespace and other comments by case or default keywords or by a user label that precedes some case or default label.

Unless I'm missing something, that's what the patch does, i.e. each annotation being added is followed by a case statement with an implicit fallthrough? For example, the first comment right after the switch statement is meant to quiet the warning generated by the first case statement,

cognet commented 6 years ago

Do you get a warning if you don't have it ? In my understanding, you're only falling through one case statement to another, so that should not happen for the first one ? Of course, it wouldn't be the first time I'm wrong :)

akopytov commented 6 years ago

You were right, it was me who misunderstood the manual :) The comment right after the switch is indeed redundant, as seen from examples in the manual. Resubmitted the patch.

cognet commented 6 years ago

Merged, thanks a lot !