File tree Expand file tree Collapse file tree 3 files changed +58
-0
lines changed
TESTS/mbedmicro-mbed/attributes Expand file tree Collapse file tree 3 files changed +58
-0
lines changed Original file line number Diff line number Diff line change @@ -145,6 +145,24 @@ int testNoReturn()
145
145
}
146
146
147
147
148
+ int testFallthrough1 (int i )
149
+ {
150
+ switch (i ) {
151
+ case 1 :
152
+ case 2 :
153
+ i *= 2 ;
154
+ MBED_FALLTHROUGH ;
155
+ default :
156
+ return i ;
157
+ }
158
+ }
159
+
160
+ int testFallthrough ()
161
+ {
162
+ return testFallthrough1 (0 );
163
+ }
164
+
165
+
148
166
int testUnreachable1 (int i )
149
167
{
150
168
switch (i ) {
Original file line number Diff line number Diff line change @@ -33,6 +33,7 @@ extern "C" {
33
33
int testPure ();
34
34
int testForceInline ();
35
35
int testNoReturn ();
36
+ int testFallthrough ();
36
37
int testUnreachable ();
37
38
int testDeprecated ();
38
39
}
@@ -59,6 +60,7 @@ Case cases[] = {
59
60
Case (" Testing PURE attribute" , test_wrapper<testPure>),
60
61
Case (" Testing FORCEINLINE attribute" , test_wrapper<testForceInline>),
61
62
Case (" Testing NORETURN attribute" , test_wrapper<testNoReturn>),
63
+ Case (" Testing FALLTHROUGH attribute" , test_wrapper<testFallthrough>),
62
64
Case (" Testing UNREACHABLE attribute" , test_wrapper<testUnreachable>),
63
65
Case (" Testing DEPRECATED attribute" , test_wrapper<testDeprecated>),
64
66
};
Original file line number Diff line number Diff line change 340
340
#endif
341
341
#endif
342
342
343
+ /* * MBED_FALLTHROUGH
344
+ * Marks a point in a switch statement where fallthrough can occur.
345
+ * Should be placed as the last statement before a label.
346
+ *
347
+ * @code
348
+ * #include "mbed_toolchain.h"
349
+ *
350
+ * int foo(int arg) {
351
+ * switch (arg) {
352
+ * case 1:
353
+ * case 2:
354
+ * case 3:
355
+ * arg *= 2;
356
+ * MBED_FALLTHROUGH;
357
+ * default:
358
+ * return arg;
359
+ * }
360
+ * }
361
+ * @endcode
362
+ */
363
+ #ifndef MBED_FALLTHROUGH
364
+ #if __cplusplus >= 201703
365
+ #define MBED_FALLTHROUGH [[fallthrough]]
366
+ #elif defined(__clang__)
367
+ #if __cplusplus >= 201103
368
+ #define MBED_FALLTHROUGH [[clang::fallthrough]]
369
+ #elif __has_attribute(fallthrough)
370
+ #define MBED_FALLTHROUGH __attribute__ ((fallthrough))
371
+ #else
372
+ #define MBED_FALLTHROUGH
373
+ #endif
374
+ #elif defined (__GNUC__) && !defined(__CC_ARM)
375
+ #define MBED_FALLTHROUGH __attribute__ ((fallthrough))
376
+ #else
377
+ #define MBED_FALLTHROUGH
378
+ #endif
379
+ #endif
380
+
343
381
/* * MBED_DEPRECATED("message string")
344
382
* Mark a function declaration as deprecated, if it used then a warning will be
345
383
* issued by the compiler possibly including the provided message. Note that not
You can’t perform that action at this time.
0 commit comments