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
Improve check for fallthrough support #2482
Conversation
#if defined(__clang__) | ||
#if (__clang_major__ >= 12) || (__clang_analyzer__) | ||
|
||
/* Supported since clang 12 and GCC 7 */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we are not supporting older compiler versions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we are the fallthrough marking won't work on those but otherwise they are still supported
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We actually have some defines about it in the cmake file. For eg CC_SUPPORTS_IMPLICIT_FALLTHROUGH
, maybe rely on it if makes sense?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this tests whether the compiler supports -Wimplicit-fallthrough not necessarily whether it supports fallthrough attribute
src/annotations.h
Outdated
|
||
/* Supported since clang 12 and GCC 7 */ | ||
#if defined __has_attribute | ||
#if __has_attribute (fallthrough) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this standard across both clang and gcc? I couldn't find good information about it so that's why I didn't use it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was more concern at what version this was introduced and whether one can rely on the check being there for all versions that support the attribute. It seems as if __attribute__((fallthrough))
was added to clang 12 (I couldn't find docs for previous versions), and I guess the macro check was added prior to that or in the same release so it should be ok.
src/annotations.h
Outdated
|
||
/* Supported since clang 12 and GCC 7 */ | ||
#if defined __has_attribute | ||
#if __has_attribute (fallthrough) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was more concern at what version this was introduced and whether one can rely on the check being there for all versions that support the attribute. It seems as if __attribute__((fallthrough))
was added to clang 12 (I couldn't find docs for previous versions), and I guess the macro check was added prior to that or in the same release so it should be ok.
Change the check for fallthrough support to check for the attribute instead of specific compiler versions.
Codecov Report
@@ Coverage Diff @@
## master #2482 +/- ##
==========================================
+ Coverage 90.04% 90.18% +0.13%
==========================================
Files 212 212
Lines 34174 34148 -26
==========================================
+ Hits 30772 30795 +23
+ Misses 3402 3353 -49
Continue to review full report at Codecov.
|
Change the check for fallthrough support to check for the attribute
instead of specific compiler versions.