mirror of
https://github.com/torvalds/linux.git
synced 2026-10-07 05:31:08 -04:00
compiler_attributes.h: Add 'fallthrough' pseudo keyword for switch/case use
Reserve the pseudo keyword 'fallthrough' for the ability to convert the
various case block /* fallthrough */ style comments to appear to be an
actual reserved word with the same gcc case block missing fallthrough
warning capability.
All switch/case blocks now should end in one of:
break;
fallthrough;
goto <label>;
return [expression];
continue;
In C mode, GCC supports the __fallthrough__ attribute since 7.1,
the same time the warning and the comment parsing were introduced.
fallthrough devolves to an empty "do {} while (0)" if the compiler
version (any version less than gcc 7) does not support the attribute.
Signed-off-by: Joe Perches <[email protected]>
Acked-by: Peter Zijlstra (Intel) <[email protected]>
Suggested-by: Dan Carpenter <[email protected]>
Cc: Miguel Ojeda <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
This commit is contained in:
1 parent
48f9bcf914
commit
294f69e662
1 file changed
+17
@@ -40,6 +40,7 @@
|
||||
# define __GCC4_has_attribute___noclone__ 1
|
||||
# define __GCC4_has_attribute___nonstring__ 0
|
||||
# define __GCC4_has_attribute___no_sanitize_address__ (__GNUC_MINOR__ >= 8)
|
||||
# define __GCC4_has_attribute___fallthrough__ 0
|
||||
#endif
|
||||
|
||||
/*
|
||||
@@ -185,6 +186,22 @@
|
||||
# define __noclone
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Add the pseudo keyword 'fallthrough' so case statement blocks
|
||||
* must end with any of these keywords:
|
||||
* break;
|
||||
* fallthrough;
|
||||
* goto <label>;
|
||||
* return [expression];
|
||||
*
|
||||
* gcc: https://gcc.gnu.org/onlinedocs/gcc/Statement-Attributes.html#Statement-Attributes
|
||||
*/
|
||||
#if __has_attribute(__fallthrough__)
|
||||
# define fallthrough __attribute__((__fallthrough__))
|
||||
#else
|
||||
# define fallthrough do {} while (0) /* fallthrough */
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Note the missing underscores.
|
||||
*
|
||||
|
||||
Reference in new issue
Block a user