mirror of
https://github.com/encounter/SDL.git
synced 2025-12-09 05:27:48 +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).
Clang before Clang 10 and GCC before GCC 7 have problems with using
__attribute__ as a sole statement and warn about a "declaration not
declaring anything", so fall back to using the /* fallthrough */ comment
if we are using those older compiler versions.
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:
@@ -758,7 +758,7 @@ SDL_iconv(SDL_iconv_t cd,
|
||||
if (ch > 0x10FFFF) {
|
||||
ch = UNKNOWN_UNICODE;
|
||||
}
|
||||
/* fallthrough */
|
||||
SDL_FALLTHROUGH;
|
||||
case ENCODING_UCS4BE:
|
||||
if (ch > 0x7FFFFFFF) {
|
||||
ch = UNKNOWN_UNICODE;
|
||||
@@ -780,7 +780,7 @@ SDL_iconv(SDL_iconv_t cd,
|
||||
if (ch > 0x10FFFF) {
|
||||
ch = UNKNOWN_UNICODE;
|
||||
}
|
||||
/* fallthrough */
|
||||
SDL_FALLTHROUGH;
|
||||
case ENCODING_UCS4LE:
|
||||
if (ch > 0x7FFFFFFF) {
|
||||
ch = UNKNOWN_UNICODE;
|
||||
|
||||
@@ -1275,7 +1275,7 @@ SDL_vsscanf(const char *text, const char *fmt, va_list ap)
|
||||
}
|
||||
}
|
||||
}
|
||||
/* Fall through to %d handling */
|
||||
SDL_FALLTHROUGH;
|
||||
case 'd':
|
||||
if (inttype == DO_LONGLONG) {
|
||||
Sint64 value;
|
||||
@@ -1323,13 +1323,13 @@ SDL_vsscanf(const char *text, const char *fmt, va_list ap)
|
||||
if (radix == 10) {
|
||||
radix = 8;
|
||||
}
|
||||
/* Fall through to unsigned handling */
|
||||
SDL_FALLTHROUGH;
|
||||
case 'x':
|
||||
case 'X':
|
||||
if (radix == 10) {
|
||||
radix = 16;
|
||||
}
|
||||
/* Fall through to unsigned handling */
|
||||
SDL_FALLTHROUGH;
|
||||
case 'u':
|
||||
if (inttype == DO_LONGLONG) {
|
||||
Uint64 value = 0;
|
||||
@@ -1815,7 +1815,7 @@ SDL_vsnprintf(SDL_OUT_Z_CAP(maxlen) char *text, size_t maxlen, const char *fmt,
|
||||
case 'p':
|
||||
case 'x':
|
||||
info.force_case = SDL_CASE_LOWER;
|
||||
/* Fall through to 'X' handling */
|
||||
SDL_FALLTHROUGH;
|
||||
case 'X':
|
||||
if (info.force_case == SDL_CASE_NOCHANGE) {
|
||||
info.force_case = SDL_CASE_UPPER;
|
||||
@@ -1826,12 +1826,12 @@ SDL_vsnprintf(SDL_OUT_Z_CAP(maxlen) char *text, size_t maxlen, const char *fmt,
|
||||
if (*fmt == 'p') {
|
||||
inttype = DO_LONG;
|
||||
}
|
||||
/* Fall through to unsigned handling */
|
||||
SDL_FALLTHROUGH;
|
||||
case 'o':
|
||||
if (info.radix == 10) {
|
||||
info.radix = 8;
|
||||
}
|
||||
/* Fall through to unsigned handling */
|
||||
SDL_FALLTHROUGH;
|
||||
case 'u':
|
||||
info.force_sign = SDL_FALSE;
|
||||
if (info.precision >= 0) {
|
||||
|
||||
Reference in New Issue
Block a user