Merge branch 'wip/otte/fallthrough' into 'master'

Add G_GNUC_FALLTHROUGH for __attribute__(fallthrough))

See merge request GNOME/glib!296
This commit is contained in:
Philip Withnall 2018-09-04 22:06:26 +00:00
commit 98f326a020
12 changed files with 45 additions and 7 deletions

View File

@ -438,6 +438,7 @@ G_GNUC_DEPRECATED_FOR
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
G_GNUC_END_IGNORE_DEPRECATIONS
G_GNUC_NORETURN
G_GNUC_FALLTHROUGH
G_GNUC_UNUSED
G_GNUC_PRINTF
G_GNUC_SCANF

View File

@ -166,9 +166,11 @@ test_data_array (guchar *buffer, gsize len,
case TEST_DATA_INT16:
case TEST_DATA_UINT16:
g_assert_cmpint (len % 2, ==, 0);
G_GNUC_FALLTHROUGH;
case TEST_DATA_INT32:
case TEST_DATA_UINT32:
g_assert_cmpint (len % 4, ==, 0);
G_GNUC_FALLTHROUGH;
case TEST_DATA_INT64:
case TEST_DATA_UINT64:
g_assert_cmpint (len % 8, ==, 0);

View File

@ -33,12 +33,14 @@ cook_piece (void)
{
case 26:
buffer[i++] = '\n';
G_GNUC_FALLTHROUGH;
case 27:
buffer[i++] = '\r';
break;
case 28:
buffer[i++] = '\r';
G_GNUC_FALLTHROUGH;
case 29:
buffer[i++] = '\n';
break;

View File

@ -2280,6 +2280,22 @@
* See the GNU C documentation for more details.
*/
/**
* G_GNUC_FALLTHROUGH:
*
* Expands to the GNU C fallthrough statement attribute if the compiler is gcc.
* This allows declaring case statement to explicitly fall through in switch
* statements. To enable this feature, use -Wimplicit-fallthrough during
* compilation.
*
* Put the attribute right before the case statement you want to fall through
* to.
*
* See the GNU C documentation for more details.
*
* Since: 2.60
*/
/**
* G_GNUC_UNUSED:
*

View File

@ -170,8 +170,11 @@ g_base64_encode_step (const guchar *in,
/* len can only be 0 1 or 2 */
switch(len)
{
case 2: *saveout++ = *inptr++;
case 1: *saveout++ = *inptr++;
case 2:
*saveout++ = *inptr++;
G_GNUC_FALLTHROUGH;
case 1:
*saveout++ = *inptr++;
}
((char *)save)[0] += len;
}

View File

@ -788,7 +788,8 @@ g_convert_with_fallback (const gchar *str,
inbytes_remaining = strlen (p);
break;
}
/* fall thru if p is NULL */
/* if p is null */
G_GNUC_FALLTHROUGH;
default:
{
int errsv = errno;

View File

@ -191,6 +191,12 @@
#define G_GNUC_NO_INSTRUMENT
#endif /* !__GNUC__ */
#if __GNUC__ > 6
#define G_GNUC_FALLTHROUGH __attribute__((fallthrough))
#else
#define G_GNUC_FALLTHROUGH
#endif /* __GNUC__ */
#if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1)
#define G_GNUC_DEPRECATED __attribute__((__deprecated__))
#else

View File

@ -2872,6 +2872,8 @@ failure:
case G_MARKUP_COLLECT_STRDUP:
if (written)
g_free (*(char **) ptr);
*(char **) ptr = NULL;
break;
case G_MARKUP_COLLECT_STRING:
*(char **) ptr = NULL;

View File

@ -2537,6 +2537,7 @@ expand_escape (const gchar *replacement,
base = 8;
p = g_utf8_next_char (p);
}
G_GNUC_FALLTHROUGH;
case '1':
case '2':
case '3':

View File

@ -372,6 +372,8 @@ parse_constant_offset (const gchar *name,
*offset = -*offset;
return TRUE;
}
else
return FALSE;
default:
return FALSE;

View File

@ -210,10 +210,7 @@ token_stream_prepare (TokenStream *stream)
break;
}
else
{
/* ↓↓↓ */
}
G_GNUC_FALLTHROUGH;
case 'a': /* 'b' */ case 'c': case 'd': case 'e': case 'f':
case 'g': case 'h': case 'i': case 'j': case 'k': case 'l':
@ -1646,6 +1643,8 @@ string_parse (TokenStream *stream,
case '\n': i++; continue;
}
G_GNUC_FALLTHROUGH;
default:
str[j++] = token[i++];
}
@ -1773,6 +1772,8 @@ bytestring_parse (TokenStream *stream,
case '\n': i++; continue;
}
G_GNUC_FALLTHROUGH;
default:
str[j++] = token[i++];
}

View File

@ -344,6 +344,7 @@ if cc.get_id() == 'gcc' or cc.get_id() == 'clang'
test_c_args = [
'-Wall',
'-Wduplicated-branches',
'-Wimplicit-fallthrough',
'-Wmisleading-indentation',
'-Wstrict-prototypes',
'-Wunused',