ROSE
0.11.145.192
src
util
ROSE_FALLTHROUGH.h
1
#ifndef ROSE_FALLTHROUGH_H
2
#define ROSE_FALLTHROUGH_H
3
4
// Marks case branches that fall through to the next case, so that the compiler does not generate
5
// "this statement may fall through" warnings (i.e., GCC).
6
//
7
// | 1|int foo(int x) {
8
// | 2| int res = 0;
9
// | 3| switch(x) {
10
// | 4| case 1: ++res;
11
// | 5| default: ++res; break;
12
// | 6| }
13
// | 7| return res;
14
// | 8|}
15
//
16
// The compiler will emit a implicit-fallthrough warning for the end of 'case 0:' at line 4.
17
//
18
// The best way is to use C++17 attributes.
19
//
20
// | 1|int foo(int x) {
21
// | 2| int res = 0;
22
// | 3| switch(x) {
23
// | 4| case 1: ++res; [[fallthrough]];
24
// | 5| default: ++res; break;
25
// | 6| }
26
// | 7| return res;
27
// | 8|}
28
//
29
// Until we support C++17 in ROSE fully, we can rely on older attributes for the GNU compiler.
30
// [[gnu::fallthrough]];
31
//
32
// | 1|int foo(int x) {
33
// | 2|#ifdef SOMETHING
34
// | 3| return x;
35
// | 4|#else
36
// | 5| ROSE_UNUSED(x);
37
// | 6| return 0;
38
// | 7|#endif
39
// | 8|}
40
//
41
// reference for gcc: https://developers.redhat.com/blog/2017/03/10/wimplicit-fallthrough-in-gcc-7
42
43
44
#if __cplusplus >= 201703L
45
#define ROSE_FALLTHROUGH [[fallthrough]]
46
#elif defined __GNUC__
47
#define ROSE_FALLTHROUGH [[gnu::fallthrough]]
48
#else
49
// this may not work as intended
50
#define ROSE_FALLTHROUGH
/* FALL THROUGH */
51
#endif
52
53
54
#endif
Generated on Mon Dec 16 2024 03:17:11 for ROSE by
1.9.8