Introduce fallthrough as a wrapper around the fallthrough attribute#10696
Introduce fallthrough as a wrapper around the fallthrough attribute#10696shindere merged 3 commits intoocaml:trunkfrom
fallthrough as a wrapper around the fallthrough attribute#10696Conversation
0b94d29 to
361f428
Compare
|
Found more cases of fallthrough to replace. |
|
I'm not sure what you're trying to achieve. For quite a while, gcc has been able to check |
|
I agree that comments in general look nicer than the attributes or my I think however that using the attributes/statement syntax has I'm unconfortable putting a semantic meaning into a comment. I think I also don't find it obvious which level to use for the warning; in my In interp.c I prefer Now, to get a better looking macro we could use simply I haven't triggered any warning report for a forgotten fallthrough |
361f428 to
a1ab72b
Compare
|
Rebased the PR to fix Changes conflicts. |
a1ab72b to
6f04eda
Compare
6f04eda to
6c31aae
Compare
|
This PR would have allowed us to avoid the slip in #11002 fixed in #11066. dra27@4882f3e adds the necessary support to There is a case for the |
2acde56 to
8a23af0
Compare
8a23af0 to
1826701
Compare
eef180c to
ea3e26a
Compare
ea3e26a to
76baaca
Compare
|
This PR (or at least the warning) would have caught this new bug before it was introduced, maybe we could revisit it? Move the detection of the attribute to configure as not to clutter the headers? |
|
However, it turns out this can be fixed by including I think we should definitely merge one of these solutions, although my preference is for @MisterDA's, as it enables the warning for clang as well. |
76baaca to
6769f0a
Compare
3c05782 to
b6013b2
Compare
b6013b2 to
00448f1
Compare
|
I've cleaned, simplified, and rebased this PR. Could this be reconsidered? |
00448f1 to
0a5215c
Compare
0a5215c to
6573cbd
Compare
Evidently, I lied.
That's the strongest point, I think. I've rebased once more, and chosen to guard definition of |
fallthrough as a wrapper around the fallthrough attribute
gasche
left a comment
There was a problem hiding this comment.
I don't have a clear opinion or expertise on these topics, but I can see that @MisterDA would be happy to get some feedback so I had a look. This looks okay: I trust @dra27's positive gut feeling, and I agree with the sentiment that proper syntax is better than a comment. I don't see a cost to this PR besides the churn and potential for regression, and arguably some benefits, so I propose to go ahead and merge it eventually.
`__has_c_attribute` is C23 and checks for `[[name]]`, `__has_attribute` is an extension of the compiler and checks for `__attribute__((name))`.
Recent compilers have introduced the -Wimplicit-fallthrough warning against the C switch fallthrough. OCaml already uses the /* fallthrough */ C comment that GCC 7 and above recognize for some level given to the warning, but the fallthrough statement is also available since C++17 and either as a language statement (expected in C2X) or as a compiler/language attribute. This commit makes use of the statement/attribute when available, with a fallback to an empty statement, and uses the new fallthrough macro wherever the comment was used. It also reorders some switches to avoid "control reaches end of non-void function" warnings when CAMLassert is disabled.
Recent compilers have introduced the
-Wimplicit-fallthroughwarningagainst the C switch fallthrough. OCaml already uses the
/* fallthrough */C comment that GCC 7 and above recognize for some level
given to the warning, but the fallthrough statement is also available
since C++17 and either as a language statement (expected in C2X) or as
a compiler/language attribute.
This commit makes use of the statement/attribute when available, or
falls back to the fallthrough comment, and uses the new
CAMLfallthroughmacro wherever the comment was used.