From f77957607778040b1ded790fa83768602f16daa1 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Wed, 26 Jul 2017 09:12:29 -0700 Subject: [PATCH] regex: work with GCC7's -Werror=implicit-fallthrough= * lib/regex_internal.h (FALLTHROUGH): New macro. * lib/regcomp.c (peek_token_bracket, parse_expression): * lib/regexec.c (check_node_accept): Use it. --- ChangeLog | 7 +++++++ lib/regcomp.c | 21 +++++++++++++++++---- lib/regex_internal.h | 8 ++++++++ lib/regexec.c | 2 +- 4 files changed, 33 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index ae2b049b41..d53d143a13 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2017-07-26 Paul Eggert + + regex: work with GCC7's -Werror=implicit-fallthrough= + * lib/regex_internal.h (FALLTHROUGH): New macro. + * lib/regcomp.c (peek_token_bracket, parse_expression): + * lib/regexec.c (check_node_accept): Use it. + 2017-07-24 Paul Eggert fts: simplify fts_build diff --git a/lib/regcomp.c b/lib/regcomp.c index 9fd4fed999..2824521213 100644 --- a/lib/regcomp.c +++ b/lib/regcomp.c @@ -2078,16 +2078,18 @@ peek_token_bracket (re_token_t *token, re_string_t *input, reg_syntax_t syntax) case '.': token->type = OP_OPEN_COLL_ELEM; break; + case '=': token->type = OP_OPEN_EQUIV_CLASS; break; + case ':': if (syntax & RE_CHAR_CLASSES) { token->type = OP_OPEN_CHAR_CLASS; break; } - /* else fall through. */ + FALLTHROUGH; default: token->type = CHARACTER; token->opr.c = c; @@ -2289,16 +2291,19 @@ parse_expression (re_string_t *regexp, regex_t *preg, re_token_t *token, } #endif break; + case OP_OPEN_SUBEXP: tree = parse_sub_exp (regexp, preg, token, syntax, nest + 1, err); if (BE (*err != REG_NOERROR && tree == NULL, 0)) return NULL; break; + case OP_OPEN_BRACKET: tree = parse_bracket_exp (regexp, dfa, token, syntax, err); if (BE (*err != REG_NOERROR && tree == NULL, 0)) return NULL; break; + case OP_BACK_REF: if (!BE (dfa->completed_bkref_map & (1 << token->opr.idx), 1)) { @@ -2315,13 +2320,14 @@ parse_expression (re_string_t *regexp, regex_t *preg, re_token_t *token, ++dfa->nbackref; dfa->has_mb_node = 1; break; + case OP_OPEN_DUP_NUM: if (syntax & RE_CONTEXT_INVALID_DUP) { *err = REG_BADRPT; return NULL; } - /* FALLTHROUGH */ + FALLTHROUGH; case OP_DUP_ASTERISK: case OP_DUP_PLUS: case OP_DUP_QUESTION: @@ -2335,7 +2341,7 @@ parse_expression (re_string_t *regexp, regex_t *preg, re_token_t *token, fetch_token (token, regexp, syntax); return parse_expression (regexp, preg, token, syntax, nest, err); } - /* else fall through */ + FALLTHROUGH; case OP_CLOSE_SUBEXP: if ((token->type == OP_CLOSE_SUBEXP) && !(syntax & RE_UNMATCHED_RIGHT_PAREN_ORD)) @@ -2343,7 +2349,7 @@ parse_expression (re_string_t *regexp, regex_t *preg, re_token_t *token, *err = REG_ERPAREN; return NULL; } - /* else fall through */ + FALLTHROUGH; case OP_CLOSE_DUP_NUM: /* We treat it as a normal character. */ @@ -2358,6 +2364,7 @@ parse_expression (re_string_t *regexp, regex_t *preg, re_token_t *token, return NULL; } break; + case ANCHOR: if ((token->opr.ctx_type & (WORD_DELIM | NOT_WORD_DELIM | WORD_FIRST | WORD_LAST)) @@ -2402,6 +2409,7 @@ parse_expression (re_string_t *regexp, regex_t *preg, re_token_t *token, it must not be "". */ fetch_token (token, regexp, syntax); return tree; + case OP_PERIOD: tree = create_token_tree (dfa, NULL, NULL, token); if (BE (tree == NULL, 0)) @@ -2412,6 +2420,7 @@ parse_expression (re_string_t *regexp, regex_t *preg, re_token_t *token, if (dfa->mb_cur_max > 1) dfa->has_mb_node = 1; break; + case OP_WORD: case OP_NOTWORD: tree = build_charclass_op (dfa, regexp->trans, @@ -2421,6 +2430,7 @@ parse_expression (re_string_t *regexp, regex_t *preg, re_token_t *token, if (BE (*err != REG_NOERROR && tree == NULL, 0)) return NULL; break; + case OP_SPACE: case OP_NOTSPACE: tree = build_charclass_op (dfa, regexp->trans, @@ -2430,12 +2440,15 @@ parse_expression (re_string_t *regexp, regex_t *preg, re_token_t *token, if (BE (*err != REG_NOERROR && tree == NULL, 0)) return NULL; break; + case OP_ALT: case END_OF_RE: return NULL; + case BACK_SLASH: *err = REG_EESCAPE; return NULL; + default: /* Must not happen? */ #ifdef DEBUG diff --git a/lib/regex_internal.h b/lib/regex_internal.h index 827020719c..d7f76d6d8f 100644 --- a/lib/regex_internal.h +++ b/lib/regex_internal.h @@ -899,4 +899,12 @@ re_string_elem_size_at (const re_string_t *pstr, Idx idx) # define __attribute_warn_unused_result__ /* empty */ #endif +#ifndef FALLTHROUGH +# if __GNUC__ < 7 +# define FALLTHROUGH ((void) 0) +# else +# define FALLTHROUGH __attribute__ ((__fallthrough__)) +# endif +#endif + #endif /* _REGEX_INTERNAL_H */ diff --git a/lib/regexec.c b/lib/regexec.c index ef52b243ad..497ba0f31d 100644 --- a/lib/regexec.c +++ b/lib/regexec.c @@ -4078,7 +4078,7 @@ check_node_accept (const re_match_context_t *mctx, const re_token_t *node, case OP_UTF8_PERIOD: if (ch >= ASCII_CHARS) return false; - /* FALLTHROUGH */ + FALLTHROUGH; #endif case OP_PERIOD: if ((ch == '\n' && !(mctx->dfa->syntax & RE_DOT_NEWLINE)) -- 2.39.5