Commit 06b8a40f by Patrick Steinhardt

Explicitly mark fallthrough cases with comments

A lot of compilers nowadays generate warnings when there are cases in a
switch statement which implicitly fall through to the next case. To
avoid this warning, the last line in the case that is falling through
can have a comment matching a regular expression, where one possible
comment body would be `/* fall through */`.

An alternative to the comment would be an explicit attribute like e.g.
`[[clang::fallthrough]` or `__attribute__ ((fallthrough))`. But GCC only
introduced support for such an attribute recently with GCC 7. Thus, and
also because the fallthrough comment is supported by most compilers, we
settle for using comments instead.

One shortcoming of that method is that compilers are very strict about
that. Most interestingly, that comment _really_ has to be the last line.
In case a closing brace follows the comment, the heuristic will fail.
parent 7c6e9175
......@@ -575,6 +575,7 @@ static int parse_hunk_body(
switch (c) {
case '\n':
prefix = 0;
/* fall through */
case ' ':
origin = GIT_DIFF_LINE_CONTEXT;
......
......@@ -770,7 +770,6 @@ int revparse__ext(
}
case '@':
{
if (spec[pos+1] == '{') {
git_object *temp_object = NULL;
......@@ -786,10 +785,8 @@ int revparse__ext(
if (temp_object != NULL)
base_rev = temp_object;
break;
} else {
/* Fall through */
}
}
/* fall through */
default:
if ((error = ensure_left_hand_identifier_is_not_known_yet(base_rev, reference)) < 0)
......
......@@ -957,7 +957,7 @@ int git_tree_entry_bypath(
* walking down the path */
if (path[filename_len + 1] != '\0')
break;
/* fall through */
case '\0':
/* If there are no more components in the path, return
* this entry */
......
......@@ -478,9 +478,11 @@ uint32_t git__hash(const void *key, int len, uint32_t seed)
switch(len & 3) {
case 3: k1 ^= tail[2] << 16;
/* fall through */
case 2: k1 ^= tail[1] << 8;
/* fall through */
case 1: k1 ^= tail[0];
MURMUR_BLOCK();
MURMUR_BLOCK();
}
h1 ^= len;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment