mirror of
https://github.com/libsdl-org/SDL.git
synced 2025-10-12 12:55:59 +00:00
Add and use SDL_FALLTHROUGH
for fallthroughs
Case fallthrough warnings can be suppressed using the __fallthrough__ compiler attribute. Unfortunately, not all compilers have this attribute, or even have __has_attribute to check if they have the __fallthrough__ attribute. [[fallthrough]] is also available in C++17 and the next C2x, but not everyone uses C++17 or C2x. So define the SDL_FALLTHROUGH macro to deal with those problems - if we are using C++17 or C2x, it expands to [[fallthrough]]; else if the compiler has __has_attribute and has the __fallthrough__ attribute, then it expands to __attribute__((__fallthrough__)); else it expands to an empty statement, with a /* fallthrough */ comment (it's a do {} while (0) statement, because users of this macro need to use a semicolon, because [[fallthrough]] and __attribute__((__fallthrough__)) require a semicolon). Applications using SDL are also free to use this macro (because it is defined in begin_code.h). All existing /* fallthrough */ comments have been replaced with this macro. Some of them were unnecessary because they were the last case in a switch; using SDL_FALLTHROUGH in those cases would result in a compile error on compilers that support __fallthrough__, for having a __attribute__((__fallthrough__)) statement that didn't immediately precede a case label.
This commit is contained in:
@@ -479,14 +479,14 @@ do { \
|
||||
#define DUFFS_LOOP8(pixel_copy_increment, width) \
|
||||
{ int n = (width+7)/8; \
|
||||
switch (width & 7) { \
|
||||
case 0: do { pixel_copy_increment; /* fallthrough */ \
|
||||
case 7: pixel_copy_increment; /* fallthrough */ \
|
||||
case 6: pixel_copy_increment; /* fallthrough */ \
|
||||
case 5: pixel_copy_increment; /* fallthrough */ \
|
||||
case 4: pixel_copy_increment; /* fallthrough */ \
|
||||
case 3: pixel_copy_increment; /* fallthrough */ \
|
||||
case 2: pixel_copy_increment; /* fallthrough */ \
|
||||
case 1: pixel_copy_increment; /* fallthrough */ \
|
||||
case 0: do { pixel_copy_increment; SDL_FALLTHROUGH; \
|
||||
case 7: pixel_copy_increment; SDL_FALLTHROUGH; \
|
||||
case 6: pixel_copy_increment; SDL_FALLTHROUGH; \
|
||||
case 5: pixel_copy_increment; SDL_FALLTHROUGH; \
|
||||
case 4: pixel_copy_increment; SDL_FALLTHROUGH; \
|
||||
case 3: pixel_copy_increment; SDL_FALLTHROUGH; \
|
||||
case 2: pixel_copy_increment; SDL_FALLTHROUGH; \
|
||||
case 1: pixel_copy_increment; \
|
||||
} while ( --n > 0 ); \
|
||||
} \
|
||||
}
|
||||
@@ -495,10 +495,10 @@ do { \
|
||||
#define DUFFS_LOOP4(pixel_copy_increment, width) \
|
||||
{ int n = (width+3)/4; \
|
||||
switch (width & 3) { \
|
||||
case 0: do { pixel_copy_increment; /* fallthrough */ \
|
||||
case 3: pixel_copy_increment; /* fallthrough */ \
|
||||
case 2: pixel_copy_increment; /* fallthrough */ \
|
||||
case 1: pixel_copy_increment; /* fallthrough */ \
|
||||
case 0: do { pixel_copy_increment; SDL_FALLTHROUGH; \
|
||||
case 3: pixel_copy_increment; SDL_FALLTHROUGH; \
|
||||
case 2: pixel_copy_increment; SDL_FALLTHROUGH; \
|
||||
case 1: pixel_copy_increment; \
|
||||
} while (--n > 0); \
|
||||
} \
|
||||
}
|
||||
|
Reference in New Issue
Block a user