diff options
author | Jakub Jelinek <jakub@redhat.com> | 2016-10-08 12:53:05 +0200 |
---|---|---|
committer | Jakub Jelinek <jakub@gcc.gnu.org> | 2016-10-08 12:53:05 +0200 |
commit | 81b02905b035e7afee46c38186c95434b6d86813 (patch) | |
tree | 4947622b51f5c1b8e380d14c7173ad3d1d835182 /libcpp | |
parent | 7bad794aa005aa3ee52fc9c872051d8346c09a24 (diff) | |
download | gcc-81b02905b035e7afee46c38186c95434b6d86813.tar.gz |
invoke.texi (-Wimplicit-fallthrough): Document FALLTHRU comment style changes.
* doc/invoke.texi (-Wimplicit-fallthrough): Document FALLTHRU comment
style changes.
* lex.c (fallthrough_comment_p): Extend to handle more common FALLTHRU
comment styles.
* c-c++-common/Wimplicit-fallthrough-23.c (foo): Add further tests.
From-SVN: r240885
Diffstat (limited to 'libcpp')
-rw-r--r-- | libcpp/ChangeLog | 3 | ||||
-rw-r--r-- | libcpp/lex.c | 98 |
2 files changed, 93 insertions, 8 deletions
diff --git a/libcpp/ChangeLog b/libcpp/ChangeLog index faecb162caf..6e48566878e 100644 --- a/libcpp/ChangeLog +++ b/libcpp/ChangeLog @@ -1,5 +1,8 @@ 2016-10-08 Jakub Jelinek <jakub@redhat.com> + * lex.c (fallthrough_comment_p): Extend to handle more common FALLTHRU + comment styles. + * lex.c (fallthrough_comment_p): Fix off-by-one size comparison errors, cleanup. (_cpp_lex_direct): Allow arbitrary comments in between diff --git a/libcpp/lex.c b/libcpp/lex.c index d960aa869e4..2e0512d6428 100644 --- a/libcpp/lex.c +++ b/libcpp/lex.c @@ -2060,22 +2060,86 @@ fallthrough_comment_p (cpp_reader *pfile, const unsigned char *comment_start) from += 1 + len; } /* Whole comment contents (regex): - [ \t]*FALL(S | |-)?THR(OUGH|U)\.?[ \t]* - [ \t]*Fall((s | |-)[Tt]|t)hr(ough|u)\.?[ \t]* - [ \t]*fall(s | |-)?thr(ough|u)\.?[ \t]* + lint -fallthrough ? + */ + else if (*from == 'l') + { + size_t len = sizeof "int -fallthrough" - 1; + if ((size_t) (pfile->buffer->cur - from - 1) < len) + return false; + if (memcmp (from + 1, "int -fallthrough", len)) + return false; + from += 1 + len; + if (*from == ' ') + from++; + } + /* Whole comment contents (regex): + [ \t.!]*(ELSE |INTENTIONAL(LY)? )?FALL(S | |-)?THR(OUGH|U)[ \t.!]*(-[^\n\r]*)? + [ \t.!]*(Else |Intentional(ly)? )?Fall((s | |-)[Tt]|t)hr(ough|u)[ \t.!]*(-[^\n\r]*)? + [ \t.!]*([Ee]lse |[Ii]ntentional(ly)? )?fall(s | |-)?thr(ough|u)[ \t.!]*(-[^\n\r]*)? */ else { - while (*from == ' ' || *from == '\t') + while (*from == ' ' || *from == '\t' || *from == '.' || *from == '!') from++; unsigned char f = *from; + bool all_upper = false; + if (f == 'E' || f == 'e') + { + if ((size_t) (pfile->buffer->cur - from) + < sizeof "else fallthru" - 1) + return false; + if (f == 'E' && memcmp (from + 1, "LSE F", sizeof "LSE F" - 1) == 0) + all_upper = true; + else if (memcmp (from + 1, "lse ", sizeof "lse " - 1)) + return false; + from += sizeof "else " - 1; + if (f == 'e' && *from == 'F') + return false; + f = *from; + } + else if (f == 'I' || f == 'i') + { + if ((size_t) (pfile->buffer->cur - from) + < sizeof "intentional fallthru" - 1) + return false; + if (f == 'I' && memcmp (from + 1, "NTENTIONAL", + sizeof "NTENTIONAL" - 1) == 0) + all_upper = true; + else if (memcmp (from + 1, "ntentional", + sizeof "ntentional" - 1)) + return false; + from += sizeof "intentional" - 1; + if (*from == ' ') + { + from++; + if (all_upper && *from == 'f') + return false; + } + else if (all_upper) + { + if (memcmp (from, "LY F", sizeof "LY F" - 1)) + return false; + from += sizeof "LY " - 1; + } + else + { + if (memcmp (from, "ly ", sizeof "ly " - 1)) + return false; + from += sizeof "ly " - 1; + } + if (f == 'i' && *from == 'F') + return false; + f = *from; + } if (f != 'F' && f != 'f') return false; if ((size_t) (pfile->buffer->cur - from) < sizeof "fallthru" - 1) return false; - bool all_upper = false; if (f == 'F' && memcmp (from + 1, "ALL", sizeof "ALL" - 1) == 0) all_upper = true; + else if (all_upper) + return false; else if (memcmp (from + 1, "all", sizeof "all" - 1)) return false; from += sizeof "fall" - 1; @@ -2100,10 +2164,28 @@ fallthrough_comment_p (cpp_reader *pfile, const unsigned char *comment_start) } else from += sizeof "thru" - 1; - if (*from == '.') - from++; - while (*from == ' ' || *from == '\t') + while (*from == ' ' || *from == '\t' || *from == '.' || *from == '!') from++; + if (*from == '-') + { + from++; + if (*comment_start == '*') + { + do + { + while (*from && *from != '*' + && *from != '\n' && *from != '\r') + from++; + if (*from != '*' || from[1] == '/') + break; + from++; + } + while (1); + } + else + while (*from && *from != '\n' && *from != '\r') + from++; + } } /* C block comment. */ if (*comment_start == '*') |