Skip to content

Commit 06b8a40

Browse files
committed
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.
1 parent 7c6e917 commit 06b8a40

File tree

4 files changed

+6
-6
lines changed

4 files changed

+6
-6
lines changed

src/patch_parse.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -575,6 +575,7 @@ static int parse_hunk_body(
575575
switch (c) {
576576
case '\n':
577577
prefix = 0;
578+
/* fall through */
578579

579580
case ' ':
580581
origin = GIT_DIFF_LINE_CONTEXT;

src/revparse.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -770,7 +770,6 @@ int revparse__ext(
770770
}
771771

772772
case '@':
773-
{
774773
if (spec[pos+1] == '{') {
775774
git_object *temp_object = NULL;
776775

@@ -786,10 +785,8 @@ int revparse__ext(
786785
if (temp_object != NULL)
787786
base_rev = temp_object;
788787
break;
789-
} else {
790-
/* Fall through */
791788
}
792-
}
789+
/* fall through */
793790

794791
default:
795792
if ((error = ensure_left_hand_identifier_is_not_known_yet(base_rev, reference)) < 0)

src/tree.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -957,7 +957,7 @@ int git_tree_entry_bypath(
957957
* walking down the path */
958958
if (path[filename_len + 1] != '\0')
959959
break;
960-
960+
/* fall through */
961961
case '\0':
962962
/* If there are no more components in the path, return
963963
* this entry */

src/util.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -478,9 +478,11 @@ uint32_t git__hash(const void *key, int len, uint32_t seed)
478478

479479
switch(len & 3) {
480480
case 3: k1 ^= tail[2] << 16;
481+
/* fall through */
481482
case 2: k1 ^= tail[1] << 8;
483+
/* fall through */
482484
case 1: k1 ^= tail[0];
483-
MURMUR_BLOCK();
485+
MURMUR_BLOCK();
484486
}
485487

486488
h1 ^= len;

0 commit comments

Comments
 (0)