-
Notifications
You must be signed in to change notification settings - Fork 24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make fallthroughs explicit in lsqpack.c #57
base: master
Are you sure you want to change the base?
Conversation
Using `__attribute__((fallthrough));` informs the compiler, in a way it understands, that the fallthrough is explicit and wanted. This allows for the enablement of `-Wimplicit-fallthrough`, which throws warnings/errors for implicit fallthroughs, of which several exist in this file. Using `-Wimplicit-fallthrough` prevents unwanted fallthroughs.
Still prefer |
@litespeedtech - We could use a macro instead, if that seems better to you, but I do think the fallthrough should be marked using something standards compliant so that compilers know how to interpret it. |
This macro, for instance, could work: https://github.com/hercules-team/augeas/pull/836/files
|
|
@litespeedtech - I hear you wanting to maintain readability and compatibility with older compilers. The macro I included above maintains readability while providing a mechanism that newer compilers can use to insert a standards-compliant explicit fallthrough marking; older compilers will be unaffected. This can be used to make the code interoperable with codebases using I'm afraid |
I've updated the PR to use |
As an update, there are implicit fallthroughs without comments before them here: Are these meant to fallthrough? Even if you don't think supporting LLVM's |
What you are proposing, @r-barnes, seems like busywork. The compiler already does the right thing regarding fall-throughs. This code works fine without Also, be mindful that beauty is in the eye of the beholder! |
@dtikhonov I'm afraid enabling the From a language standards perspective, explicit fallthrough indications are part of the C23 language standard, so I anticipate both that the use of comments as a fallthrough annotation will decrease over time in favour of standardization. Other large projects have found it valuable to remove implicit fallthroughs and have, repeatedly, found bugs. It's not busy work to ensure one's code is safe and can communicate its safety. Even if you're not on board with the idea of using a more standard way to communicate fallthroughs, your code includes unannotated fallthroughs which might be bugs (see the three links a couple of messages up). I wish you would clarify whether or not these fallthroughs are intentional.
|
Yes: the code is obvious about it, with names like "state" and "resume." |
@dtikhonov : I didn't find it to be obvious. I've put up #58 to add fallthrough comments in the style you said you preferred. |
Made some updates regarding this, please check the latest code. should make everybody happy. :-) |
@r-barnes which compiler are you using? Here is an example where no warning is produced by either gcc or clang: https://godbolt.org/z/MG1q8964f Was there actually a warning that your change fixed? |
Алё гараж? @r-barnes? Show me the warnings. What was this change about? |
Using
__attribute__((fallthrough));
informs the compiler, in a way it understands, that the fallthrough is explicit and wanted.This allows for the enablement of
-Wimplicit-fallthrough
, which throws warnings/errors for implicit fallthroughs, of which several exist in this file. Using-Wimplicit-fallthrough
prevents unwanted fallthroughs.