diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 7ac5d8a98..74eceb342 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -10,7 +10,7 @@ permissions: contents: read env: - CFLAGS_GCC_STYLE: '-Wall -Wextra -pedantic -Wdeclaration-after-statement -Wshadow -Wno-overlength-strings' + CFLAGS_GCC_STYLE: '-Wall -Wextra -pedantic -Wdeclaration-after-statement -Wshadow -Wno-overlength-strings -Wimplicit-fallthrough' CFLAGS_MSVC: '/W3' CFLAGS_SOLARIS_CC: '-errtags=yes -erroff=E_STATEMENT_NOT_REACHED' CMAKE_FLAGS: '-Wdev -Werror=dev -Wdeprecated -Werror=deprecated --warn-uninitialized' diff --git a/.github/workflows/dev.yml b/.github/workflows/dev.yml index abf7c8baf..e77f696c7 100644 --- a/.github/workflows/dev.yml +++ b/.github/workflows/dev.yml @@ -10,7 +10,7 @@ permissions: contents: read env: - CFLAGS_GCC_STYLE: '-Wall -Wextra -pedantic -Wdeclaration-after-statement -Wshadow -Wno-overlength-strings' + CFLAGS_GCC_STYLE: '-Wall -Wextra -pedantic -Wdeclaration-after-statement -Wshadow -Wno-overlength-strings -Wimplicit-fallthrough' CFLAGS_MSVC: '/W3' CMAKE_FLAGS: '-Wdev -Werror=dev -Wdeprecated -Werror=deprecated --warn-uninitialized' diff --git a/src/pcre2_auto_possess.c b/src/pcre2_auto_possess.c index 049b71593..2f706b791 100644 --- a/src/pcre2_auto_possess.c +++ b/src/pcre2_auto_possess.c @@ -804,21 +804,21 @@ for(;;) case OP_NOT_DIGIT: invert_bits = TRUE; - /* Fall through */ + PCRE2_FALLTHROUGH /* Fall through */ case OP_DIGIT: set2 = (const uint8_t *)(cb->cbits + cbit_digit); break; case OP_NOT_WHITESPACE: invert_bits = TRUE; - /* Fall through */ + PCRE2_FALLTHROUGH /* Fall through */ case OP_WHITESPACE: set2 = (const uint8_t *)(cb->cbits + cbit_space); break; case OP_NOT_WORDCHAR: invert_bits = TRUE; - /* Fall through */ + PCRE2_FALLTHROUGH /* Fall through */ case OP_WORDCHAR: set2 = (const uint8_t *)(cb->cbits + cbit_word); break; @@ -1101,7 +1101,7 @@ for(;;) case OP_NCLASS: if (chr > 255) return FALSE; - /* Fall through */ + PCRE2_FALLTHROUGH /* Fall through */ case OP_CLASS: if (chr > 255) break; diff --git a/src/pcre2_compile.c b/src/pcre2_compile.c index 64ceb8048..fbb1cecce 100644 --- a/src/pcre2_compile.c +++ b/src/pcre2_compile.c @@ -1936,7 +1936,7 @@ else if (c >= CHAR_8) break; - /* Fall through */ + PCRE2_FALLTHROUGH /* Fall through */ /* \0 always starts an octal number, but we may drop through to here with a larger first octal digit. The original code used just to take the least @@ -2908,21 +2908,21 @@ switch(escape) { case ESC_D: prop = ESC_P; - /* Fall through */ + PCRE2_FALLTHROUGH /* Fall through */ case ESC_d: ascii_option = PCRE2_EXTRA_ASCII_BSD; break; case ESC_S: prop = ESC_P; - /* Fall through */ + PCRE2_FALLTHROUGH /* Fall through */ case ESC_s: ascii_option = PCRE2_EXTRA_ASCII_BSS; break; case ESC_W: prop = ESC_P; - /* Fall through */ + PCRE2_FALLTHROUGH /* Fall through */ case ESC_w: ascii_option = PCRE2_EXTRA_ASCII_BSW; break; @@ -4560,7 +4560,7 @@ while (ptr < ptrend) default: PCRE2_DEBUG_UNREACHABLE(); - /* Fall through */ + PCRE2_FALLTHROUGH /* Fall through */ case ESC_A: case ESC_Z: @@ -5224,7 +5224,7 @@ while (ptr < ptrend) ++ptr; goto FAILED_FORWARD; } - /* Fall through */ + PCRE2_FALLTHROUGH /* Fall through */ case CHAR_0: case CHAR_1: case CHAR_2: case CHAR_3: case CHAR_4: case CHAR_5: case CHAR_6: case CHAR_7: case CHAR_8: case CHAR_9: @@ -5974,7 +5974,7 @@ for (;;) case OP_UCP_WORD_BOUNDARY: case OP_NOT_UCP_WORD_BOUNDARY: if (!skipassert) return code; - /* Fall through */ + PCRE2_FALLTHROUGH /* Fall through */ case OP_CALLOUT: case OP_CREF: @@ -6493,7 +6493,7 @@ for (;; pptr++) case META_PRUNE: case META_SKIP: cb->had_pruneorskip = TRUE; - /* Fall through */ + PCRE2_FALLTHROUGH /* Fall through */ case META_COMMIT: case META_FAIL: *code++ = verbops[(meta - META_MARK) >> 16]; @@ -6518,7 +6518,7 @@ for (;; pptr++) case META_PRUNE_ARG: case META_SKIP_ARG: cb->had_pruneorskip = TRUE; - /* Fall through */ + PCRE2_FALLTHROUGH /* Fall through */ case META_MARK: case META_COMMIT_ARG: VERB_ARG: @@ -7498,7 +7498,7 @@ for (;; pptr++) group_return = -1; /* Set "may match empty string" */ /* Now treat as a repeated OP_BRA. */ - /* Fall through */ + PCRE2_FALLTHROUGH /* Fall through */ /* If previous was a bracket group, we may have to replicate it in certain cases. Note that at this point we can encounter only the "basic" @@ -8348,7 +8348,7 @@ for (;; pptr++) if ((options & PCRE2_UCP) != 0 && (xoptions & PCRE2_EXTRA_ASCII_BSW) == 0) meta_arg = (meta_arg == ESC_B)? OP_NOT_UCP_WORD_BOUNDARY : OP_UCP_WORD_BOUNDARY; - /* Fall through */ + PCRE2_FALLTHROUGH /* Fall through */ case ESC_A: if (cb->max_lookbehind == 0) cb->max_lookbehind = 1; @@ -9282,7 +9282,7 @@ do { case OP_EXACT: scode += IMM2_SIZE; - /* Fall through */ + PCRE2_FALLTHROUGH /* Fall through */ case OP_CHAR: case OP_PLUS: @@ -9295,7 +9295,7 @@ do { case OP_EXACTI: scode += IMM2_SIZE; - /* Fall through */ + PCRE2_FALLTHROUGH /* Fall through */ case OP_CHARI: case OP_PLUSI: @@ -9727,7 +9727,7 @@ for (;; pptr++) case META_BACKREF_BYNAME: if ((cb->external_options & PCRE2_MATCH_UNSET_BACKREF) != 0) goto ISNOTFIXED; - /* Fall through */ + PCRE2_FALLTHROUGH /* Fall through */ case META_RECURSE_BYNAME: { @@ -9776,7 +9776,7 @@ for (;; pptr++) goto RECURSE_OR_BACKREF_LENGTH; } - /* Fall through */ + PCRE2_FALLTHROUGH /* Fall through */ /* For groups >= 10 - picking up group twice does no harm. */ /* A true recursion implies not fixed length, but a subroutine call may @@ -9856,7 +9856,7 @@ for (;; pptr++) case META_CAPTURE: group = META_DATA(*pptr); - /* Fall through */ + PCRE2_FALLTHROUGH /* Fall through */ case META_ATOMIC: case META_NOCAPTURE: @@ -9903,7 +9903,7 @@ for (;; pptr++) else itemlength = (max - 1) * lastitemlength; break; } - /* Fall through */ + PCRE2_FALLTHROUGH /* Fall through */ /* Any other item means this branch does not have a fixed length. */ diff --git a/src/pcre2_compile_class.c b/src/pcre2_compile_class.c index 47d151387..edd5ab316 100644 --- a/src/pcre2_compile_class.c +++ b/src/pcre2_compile_class.c @@ -65,7 +65,7 @@ b) none of the cases here: #define CLASS_END_CASES(meta) \ default: \ PCRE2_ASSERT((meta) <= META_END); \ - /* Fall through */ \ + PCRE2_FALLTHROUGH /* Fall through */ \ case META_CLASS: \ case META_CLASS_NOT: \ case META_CLASS_EMPTY: \ @@ -2169,7 +2169,7 @@ switch (meta) } ptr++; - /* Fall through */ + PCRE2_FALLTHROUGH /* Fall through */ default: /* Scan forward characters, ranges, and properties. diff --git a/src/pcre2_convert.c b/src/pcre2_convert.c index 10d5acc0d..6b1da1ba8 100644 --- a/src/pcre2_convert.c +++ b/src/pcre2_convert.c @@ -226,7 +226,7 @@ while (plength > 0) posix++; continue; /* With next character after :] */ } - /* Fall through */ + PCRE2_FALLTHROUGH /* Fall through */ case POSIX_CLASS_NOT_STARTED: if (c == CHAR_LEFT_SQUARE_BRACKET) @@ -321,7 +321,7 @@ while (plength > 0) case CHAR_LEFT_PARENTHESIS: bracount++; - /* Fall through */ + PCRE2_FALLTHROUGH /* Fall through */ case CHAR_QUESTION_MARK: case CHAR_PLUS: @@ -329,7 +329,7 @@ while (plength > 0) case CHAR_RIGHT_CURLY_BRACKET: case CHAR_VERTICAL_LINE: if (!extended) goto ESCAPE_LITERAL; - /* Fall through */ + PCRE2_FALLTHROUGH /* Fall through */ case CHAR_DOT: case CHAR_DOLLAR_SIGN: @@ -358,7 +358,7 @@ while (plength > 0) posix_state = POSIX_ANCHORED; goto COPY_SPECIAL; } - /* Fall through */ + PCRE2_FALLTHROUGH /* Fall through */ default: if (c < 255 && strchr(pcre2_escaped_literals, c) != NULL) diff --git a/src/pcre2_dfa_match.c b/src/pcre2_dfa_match.c index c74d07dc0..3a7902454 100644 --- a/src/pcre2_dfa_match.c +++ b/src/pcre2_dfa_match.c @@ -2328,7 +2328,7 @@ for (;;) case 0x2029: #endif /* Not EBCDIC */ if (mb->bsr_convention == PCRE2_BSR_ANYCRLF) break; - /* Fall through */ + PCRE2_FALLTHROUGH /* Fall through */ case CHAR_LF: ADD_NEW(state_offset + 1, 0); @@ -2440,7 +2440,7 @@ for (;;) caseless = TRUE; codevalue -= OP_STARI - OP_STAR; - /* Fall through */ + PCRE2_FALLTHROUGH /* Fall through */ case OP_PLUS: case OP_MINPLUS: case OP_POSPLUS: @@ -2484,7 +2484,7 @@ for (;;) case OP_NOTPOSQUERYI: caseless = TRUE; codevalue -= OP_STARI - OP_STAR; - /* Fall through */ + PCRE2_FALLTHROUGH /* Fall through */ case OP_QUERY: case OP_MINQUERY: case OP_POSQUERY: @@ -2525,7 +2525,7 @@ for (;;) case OP_NOTPOSSTARI: caseless = TRUE; codevalue -= OP_STARI - OP_STAR; - /* Fall through */ + PCRE2_FALLTHROUGH /* Fall through */ case OP_STAR: case OP_MINSTAR: case OP_POSSTAR: @@ -2562,7 +2562,7 @@ for (;;) case OP_NOTEXACTI: caseless = TRUE; codevalue -= OP_STARI - OP_STAR; - /* Fall through */ + PCRE2_FALLTHROUGH /* Fall through */ case OP_EXACT: case OP_NOTEXACT: count = current_state->count; /* Number already matched */ @@ -2597,7 +2597,7 @@ for (;;) case OP_NOTPOSUPTOI: caseless = TRUE; codevalue -= OP_STARI - OP_STAR; - /* Fall through */ + PCRE2_FALLTHROUGH /* Fall through */ case OP_UPTO: case OP_MINUPTO: case OP_POSUPTO: diff --git a/src/pcre2_jit_char_inc.h b/src/pcre2_jit_char_inc.h index 475895405..864a5fdeb 100644 --- a/src/pcre2_jit_char_inc.h +++ b/src/pcre2_jit_char_inc.h @@ -570,7 +570,7 @@ while (*cc == XCL_PROP || *cc == XCL_NOTPROP) break; } compares++; - /* Fall through */ + PCRE2_FALLTHROUGH /* Fall through */ case PT_SC: status |= XCLASS_HAS_SCRIPT; @@ -770,7 +770,7 @@ if (status & XCLASS_NEEDS_UCD) case PT_SCX: if (cc[-1] == XCL_NOTPROP) break; - /* Fall through */ + PCRE2_FALLTHROUGH /* Fall through */ case PT_SC: compares--; diff --git a/src/pcre2_jit_compile.c b/src/pcre2_jit_compile.c index f50a73cd1..af8ca45ad 100644 --- a/src/pcre2_jit_compile.c +++ b/src/pcre2_jit_compile.c @@ -1245,7 +1245,7 @@ while (cc < ccend) case OP_DNREFI: case OP_DNREF: locals_size = ref_update_local_size(common, cc, locals_size); - /* Fall through */ + PCRE2_FALLTHROUGH /* Fall through */ case OP_DNCREF: count = GET2(cc, 1 + IMM2_SIZE); slot = common->name_table + GET2(cc, 1) * common->name_entry_size; @@ -1284,7 +1284,7 @@ while (cc < ccend) case OP_THEN_ARG: common->has_then = TRUE; common->control_head_ptr = 1; - /* Fall through. */ + PCRE2_FALLTHROUGH /* Fall through */ case OP_COMMIT_ARG: case OP_PRUNE_ARG: @@ -1334,7 +1334,7 @@ while (cc < ccend) if (common->utf && locals_size <= 3 * SSIZE_OF(sw)) locals_size = 3 * SSIZE_OF(sw); #endif - /* Fall through */ + PCRE2_FALLTHROUGH /* Fall through */ default: cc = next_opcode(common, cc); if (cc == NULL) @@ -1483,7 +1483,7 @@ do case OP_TYPEMINPLUS: if (count == 2) count = 3; - /* Fall through */ + PCRE2_FALLTHROUGH /* Fall through */ case OP_TYPESTAR: case OP_TYPEPLUS: @@ -1512,7 +1512,7 @@ do case OP_TYPEMINUPTO: case OP_TYPEPOSUPTO: cc += IMM2_SIZE; - /* Fall through */ + PCRE2_FALLTHROUGH /* Fall through */ case OP_TYPEQUERY: case OP_TYPEMINQUERY: @@ -1533,7 +1533,7 @@ do case OP_NOTMINPLUSI: if (count == 2) count = 3; - /* Fall through */ + PCRE2_FALLTHROUGH /* Fall through */ case OP_STAR: case OP_PLUS: @@ -1586,7 +1586,7 @@ do case OP_NOTEXACTI: case OP_NOTPOSUPTOI: cc += IMM2_SIZE; - /* Fall through */ + PCRE2_FALLTHROUGH /* Fall through */ case OP_QUERY: case OP_MINQUERY: @@ -1626,7 +1626,7 @@ do case OP_CRMINPLUS: if (count == 2) count = 3; - /* Fall through */ + PCRE2_FALLTHROUGH /* Fall through */ case OP_CRSTAR: case OP_CRPLUS: @@ -1648,7 +1648,7 @@ do } cc += 2 * IMM2_SIZE; - /* Fall through */ + PCRE2_FALLTHROUGH /* Fall through */ case OP_CRQUERY: case OP_CRMINQUERY: case OP_CRPOSQUERY: @@ -2268,7 +2268,7 @@ while (cc < ccend) default: stack_restore = TRUE; - /* Fall through. */ + PCRE2_FALLTHROUGH /* Fall through */ case OP_NOT_WORD_BOUNDARY: case OP_WORD_BOUNDARY: @@ -5947,7 +5947,7 @@ while (TRUE) { case OP_CHARI: caseless = TRUE; - /* Fall through */ + PCRE2_FALLTHROUGH /* Fall through */ case OP_CHAR: last = FALSE; cc++; @@ -5984,7 +5984,7 @@ while (TRUE) case OP_MINPLUSI: case OP_POSPLUSI: caseless = TRUE; - /* Fall through */ + PCRE2_FALLTHROUGH /* Fall through */ case OP_PLUS: case OP_MINPLUS: case OP_POSPLUS: @@ -5993,7 +5993,7 @@ while (TRUE) case OP_EXACTI: caseless = TRUE; - /* Fall through */ + PCRE2_FALLTHROUGH /* Fall through */ case OP_EXACT: repeat = GET2(cc, 1); last = FALSE; @@ -6004,7 +6004,7 @@ while (TRUE) case OP_MINQUERYI: case OP_POSQUERYI: caseless = TRUE; - /* Fall through */ + PCRE2_FALLTHROUGH /* Fall through */ case OP_QUERY: case OP_MINQUERY: case OP_POSQUERY: @@ -6136,7 +6136,7 @@ while (TRUE) case OP_NOT: case OP_NOTI: cc++; - /* Fall through. */ + PCRE2_FALLTHROUGH /* Fall through */ case OP_NOT_DIGIT: case OP_NOT_WHITESPACE: case OP_NOT_WORDCHAR: @@ -6219,7 +6219,7 @@ while (TRUE) case OP_CRMINQUERY: case OP_CRPOSQUERY: last = FALSE; - /* Fall through */ + PCRE2_FALLTHROUGH /* Fall through */ case OP_CRSTAR: case OP_CRMINSTAR: case OP_CRPOSSTAR: diff --git a/src/pcre2_match.c b/src/pcre2_match.c index 1591219d4..53f9080b0 100644 --- a/src/pcre2_match.c +++ b/src/pcre2_match.c @@ -970,7 +970,7 @@ fprintf(stderr, "++ %2ld op=%3d %s\n", Fecode - mb->start_code, *Fecode, Fecode += 1 + LINK_SIZE; continue; } - /* Fall through */ + PCRE2_FALLTHROUGH /* Fall through */ /* OP_END itself can never be reached within a recursion because that is picked up when the OP_KET that always precedes OP_END is reached. */ @@ -1054,7 +1054,7 @@ fprintf(stderr, "++ %2ld op=%3d %s\n", Fecode - mb->start_code, *Fecode, mb->hitend = TRUE; if (mb->partial > 1) return PCRE2_ERROR_PARTIAL; } - /* Fall through */ + PCRE2_FALLTHROUGH /* Fall through */ /* Match any single character whatsoever. */ @@ -6062,7 +6062,7 @@ fprintf(stderr, "++ %2ld op=%3d %s\n", Fecode - mb->start_code, *Fecode, assert_accept_frame->offset_top * sizeof(PCRE2_SIZE)); Foffset_top = assert_accept_frame->offset_top; - /* Fall through */ + PCRE2_FALLTHROUGH /* Fall through */ /* In the case of a match, the captures have already been put into the current frame. */ @@ -6360,7 +6360,7 @@ fprintf(stderr, "++ %2ld op=%3d %s\n", Fecode - mb->start_code, *Fecode, case OP_ASSERTBACK_NA: if (branch_start[1 + LINK_SIZE] == OP_VREVERSE && Feptr != P->eptr) RRETURN(MATCH_NOMATCH); - /* Fall through */ + PCRE2_FALLTHROUGH /* Fall through */ case OP_ASSERT_NA: if (Feptr > mb->last_used_ptr) mb->last_used_ptr = Feptr; @@ -6374,12 +6374,12 @@ fprintf(stderr, "++ %2ld op=%3d %s\n", Fecode - mb->start_code, *Fecode, case OP_ASSERTBACK: if (branch_start[1 + LINK_SIZE] == OP_VREVERSE && Feptr != P->eptr) RRETURN(MATCH_NOMATCH); - /* Fall through */ + PCRE2_FALLTHROUGH /* Fall through */ case OP_ASSERT: if (Feptr > mb->last_used_ptr) mb->last_used_ptr = Feptr; Feptr = P->eptr; - /* Fall through */ + PCRE2_FALLTHROUGH /* Fall through */ /* For an atomic group, discard internal backtracking points. We must also ensure that any remaining branches within the top-level of the group @@ -6403,7 +6403,7 @@ fprintf(stderr, "++ %2ld op=%3d %s\n", Fecode - mb->start_code, *Fecode, case OP_ASSERTBACK_NOT: if (branch_start[1 + LINK_SIZE] == OP_VREVERSE && Feptr != P->eptr) RRETURN(MATCH_NOMATCH); - /* Fall through */ + PCRE2_FALLTHROUGH /* Fall through */ case OP_ASSERT_NOT: RRETURN(MATCH_MATCH); @@ -6537,7 +6537,7 @@ fprintf(stderr, "++ %2ld op=%3d %s\n", Fecode - mb->start_code, *Fecode, if ((mb->moptions & PCRE2_NOTEOL) != 0) RRETURN(MATCH_NOMATCH); if ((mb->poptions & PCRE2_DOLLAR_ENDONLY) == 0) goto ASSERT_NL_OR_EOS; - /* Fall through */ + PCRE2_FALLTHROUGH /* Fall through */ /* Unconditional end of subject assertion (\z). */ case OP_EOD: @@ -7938,7 +7938,7 @@ for(;;) new_start_match = mb->verb_skip_ptr; break; } - /* Fall through */ + PCRE2_FALLTHROUGH /* Fall through */ /* NOMATCH and PRUNE advance by one character. THEN at this level acts exactly like PRUNE. Unset ignore SKIP-with-argument. */ diff --git a/src/pcre2_printint_inc.h b/src/pcre2_printint_inc.h index 3aae71fac..4dd689e38 100644 --- a/src/pcre2_printint_inc.h +++ b/src/pcre2_printint_inc.h @@ -583,7 +583,7 @@ if (type == OP_XCLASS) { case XCL_NOTPROP: notch = "^"; - /* Fall through */ + PCRE2_FALLTHROUGH /* Fall through */ case XCL_PROP: { unsigned int ptype = *ccode++; @@ -773,7 +773,7 @@ for(;;) case OP_MINQUERYI: case OP_POSQUERYI: flag = "/i"; - /* Fall through */ + PCRE2_FALLTHROUGH /* Fall through */ case OP_STAR: case OP_MINSTAR: case OP_POSSTAR: @@ -812,7 +812,7 @@ for(;;) case OP_MINUPTOI: case OP_POSUPTOI: flag = "/i"; - /* Fall through */ + PCRE2_FALLTHROUGH /* Fall through */ case OP_EXACT: case OP_UPTO: case OP_MINUPTO: @@ -845,7 +845,7 @@ for(;;) case OP_NOTI: flag = "/i"; - /* Fall through */ + PCRE2_FALLTHROUGH /* Fall through */ case OP_NOT: fprintf(f, " %s [^", flag); extra = print_char(f, code + 1, utf); @@ -862,7 +862,7 @@ for(;;) case OP_NOTMINQUERYI: case OP_NOTPOSQUERYI: flag = "/i"; - /* Fall through */ + PCRE2_FALLTHROUGH /* Fall through */ case OP_NOTSTAR: case OP_NOTMINSTAR: @@ -883,7 +883,7 @@ for(;;) case OP_NOTMINUPTOI: case OP_NOTPOSUPTOI: flag = "/i"; - /* Fall through */ + PCRE2_FALLTHROUGH /* Fall through */ case OP_NOTEXACT: case OP_NOTUPTO: @@ -908,7 +908,7 @@ for(;;) case OP_REFI: flag = "/i"; - /* Fall through */ + PCRE2_FALLTHROUGH /* Fall through */ case OP_REF: fprintf(f, " %s \\g{%d}", flag, GET2(code, 1)); i = (*code == OP_REFI)? code[1 + IMM2_SIZE] : 0; @@ -918,7 +918,7 @@ for(;;) case OP_DNREFI: flag = "/i"; - /* Fall through */ + PCRE2_FALLTHROUGH /* Fall through */ case OP_DNREF: { PCRE2_SPTR entry = nametable + (GET2(code, 1) * nesize) + IMM2_SIZE; @@ -1081,7 +1081,7 @@ for(;;) case OP_CIRCM: case OP_DOLLM: flag = "/m"; - /* Fall through */ + PCRE2_FALLTHROUGH /* Fall through */ /* Anything else is just an item with no data, but possibly a flag. */ diff --git a/src/pcre2_study.c b/src/pcre2_study.c index 38400e698..5dc339b0d 100644 --- a/src/pcre2_study.c +++ b/src/pcre2_study.c @@ -175,7 +175,7 @@ for (;;) cc += 1 + LINK_SIZE; break; } - /* Fall through */ + PCRE2_FALLTHROUGH /* Fall through */ case OP_ONCE: case OP_SCRIPT_RUN: @@ -252,7 +252,7 @@ for (;;) case OP_ASSERT_SCS: case OP_ASSERTBACK_NA: do cc += GET(cc, 1); while (*cc == OP_ALT); - /* Fall through */ + PCRE2_FALLTHROUGH /* Fall through */ /* Skip over things that don't match chars */ @@ -352,7 +352,7 @@ for (;;) case OP_PROP: case OP_NOTPROP: cc += 2; - /* Fall through */ + PCRE2_FALLTHROUGH /* Fall through */ case OP_NOT_DIGIT: case OP_DIGIT: @@ -433,7 +433,7 @@ for (;;) case OP_CRMINPLUS: case OP_CRPOSPLUS: branchlength++; - /* Fall through */ + PCRE2_FALLTHROUGH /* Fall through */ case OP_CRSTAR: case OP_CRMINSTAR: @@ -1303,7 +1303,7 @@ do case OP_PROP: if (ncode[1] != PT_CLIST) break; - /* Fall through */ + PCRE2_FALLTHROUGH /* Fall through */ case OP_ANYNL: case OP_CHAR: case OP_CHARI: @@ -1327,7 +1327,7 @@ do tcode = ncode; continue; /* With the following significant opcode */ } - /* Fall through */ + PCRE2_FALLTHROUGH /* Fall through */ /* For a group bracket or a positive assertion without an immediately following mandatory setting, recurse to set bits from within the @@ -1455,7 +1455,7 @@ do case OP_EXACT: tcode += IMM2_SIZE; - /* Fall through */ + PCRE2_FALLTHROUGH /* Fall through */ case OP_CHAR: case OP_PLUS: case OP_MINPLUS: @@ -1466,7 +1466,7 @@ do case OP_EXACTI: tcode += IMM2_SIZE; - /* Fall through */ + PCRE2_FALLTHROUGH /* Fall through */ case OP_CHARI: case OP_PLUSI: case OP_MINPLUSI: @@ -1602,7 +1602,8 @@ do case OP_TYPEUPTO: case OP_TYPEMINUPTO: case OP_TYPEPOSUPTO: - tcode += IMM2_SIZE; /* Fall through */ + tcode += IMM2_SIZE; + PCRE2_FALLTHROUGH /* Fall through */ case OP_TYPESTAR: case OP_TYPEMINSTAR: @@ -1783,7 +1784,7 @@ do /* It seems that the fall through comment must be outside the #ifdef if it is to avoid the gcc compiler warning. */ - /* Fall through */ + PCRE2_FALLTHROUGH /* Fall through */ /* Enter here for a negative non-XCLASS. In the 8-bit library, if we are in UTF mode, any byte with a value >= 0xc4 is a potentially valid starter @@ -1798,14 +1799,15 @@ do re->start_bitmap[24] |= 0xf0; /* Bits for 0xc4 - 0xc8 */ memset(re->start_bitmap+25, 0xff, 7); /* Bits for 0xc9 - 0xff */ } + PCRE2_FALLTHROUGH /* Fall through */ #elif PCRE2_CODE_UNIT_WIDTH != 8 SET_BIT(0xFF); /* For characters >= 255 */ + PCRE2_FALLTHROUGH /* Fall through */ #endif - /* Fall through */ /* Enter here for a positive non-XCLASS. If we have fallen through from an XCLASS, classmap will already be set; just advance the code pointer. - Otherwise, set up classmap for a a non-XCLASS and advance past it. */ + Otherwise, set up classmap for a non-XCLASS and advance past it. */ case OP_CLASS: if (*tcode == OP_XCLASS) tcode += GET(tcode, 1); else diff --git a/src/pcre2_util.h b/src/pcre2_util.h index ea8635552..0fe5b5503 100644 --- a/src/pcre2_util.h +++ b/src/pcre2_util.h @@ -127,6 +127,45 @@ the reason and the actions that should be taken if it ever triggers. */ #define PCRE2_ASSERT(x) do {} while(0) #endif +/* We define this fallthrough macro for suppressing -Wimplicit-fallthrough warnings. +Clang only allows this via an attribute, whereas other compilers (eg. GCC) match attributes +and also specially-formatted comments. + +This macro should be used with no following semicolon, and ideally with a comment: */ + +// PCRE2_FALLTHROUGH /* Fall through */ + +#ifndef PCRE2_FALLTHROUGH + +#if defined(__cplusplus) && __cplusplus >= 202002L && \ + defined(__has_cpp_attribute) +/* Standards-compatible C++ variant. */ +#if __has_cpp_attribute(fallthrough) +#define PCRE2_FALLTHROUGH [[fallthrough]]; +#endif +#elif !defined(__cplusplus) && \ + defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L && \ + defined(__has_c_attribute) +/* Standards-compatible C variant. */ +#if __has_c_attribute(fallthrough) +#define PCRE2_FALLTHROUGH [[fallthrough]]; +#endif +#elif ((defined(__clang__) && __clang_major__ >= 10) || \ + (defined(__GNUC__) && __GNUC__ >= 7)) && \ + defined(__has_attribute) +/* Clang and GCC syntax. Rule out old versions because apparently Clang at + least has a broken implementation of __has_attribute. */ +#if __has_attribute(fallthrough) +#define PCRE2_FALLTHROUGH __attribute__((fallthrough)); +#endif +#endif + +#endif /* !PCRE2_FALLTHROUGH */ + +#ifndef PCRE2_FALLTHROUGH +#define PCRE2_FALLTHROUGH +#endif + #endif /* PCRE2_UTIL_H_IDEMPOTENT_GUARD */ /* End of pcre2_util.h */ diff --git a/src/pcre2grep.c b/src/pcre2grep.c index 15bec99be..4b8887ee6 100644 --- a/src/pcre2grep.c +++ b/src/pcre2grep.c @@ -48,6 +48,8 @@ POSSIBILITY OF SUCH DAMAGE. #include "config.h" #endif +#include "pcre2_util.h" + #include #include #include @@ -2053,7 +2055,7 @@ switch (*(++string)) break; } - /* Fall through */ + PCRE2_FALLTHROUGH /* Fall through */ /* The maximum capture number is 65535, so any number greater than that will always be an unknown capture number. We just stop incrementing, in order to diff --git a/src/pcre2test.c b/src/pcre2test.c index 0c37d7311..88e570a6b 100644 --- a/src/pcre2test.c +++ b/src/pcre2test.c @@ -4445,7 +4445,7 @@ for (;;) *((uint32_t *)field) = (uint32_t)(m->value); break; } - /* Fall through */ + PCRE2_FALLTHROUGH /* Fall through */ case MOD_INT: /* Unsigned integer */ if (!isdigit(*pp)) goto INVALID_VALUE; @@ -7542,7 +7542,7 @@ if ((dat_datctl.control2 & CTL2_CALLOUT_EXTRA) != 0) case PCRE2_CALLOUT_STARTMATCH|PCRE2_CALLOUT_BACKTRACK: fprintf(f, "Backtrack\nNo other matching paths\n"); - /* Fall through */ + PCRE2_FALLTHROUGH /* Fall through */ case PCRE2_CALLOUT_STARTMATCH: fprintf(f, "New match attempt\n"); @@ -10221,7 +10221,7 @@ for (i = 0; i < MODLISTCOUNT; i++) break; default: printf("** Unknown type for modifier \"%s\"\n", m->name); - /* Fall through */ + PCRE2_FALLTHROUGH /* Fall through */ case MOD_PD: /* Pattern or subject */ case MOD_PDP: /* As PD, OK for Perl-compatible test */ is_pattern = for_pattern;