clang-format: Fix crasher on weird comments.

Crashing input:
  /\
  / comment

llvm-svn: 226454
This commit is contained in:
Daniel Jasper 2015-01-19 11:49:32 +00:00
parent 6c6e589c1f
commit 9b79efb51f
2 changed files with 5 additions and 4 deletions

View File

@ -838,10 +838,8 @@ private:
(!Current.Previous || Current.Previous->isNot(tok::l_square))) {
Current.Type = TT_BinaryOperator;
} else if (Current.is(tok::comment)) {
if (Current.TokenText.startswith("//"))
Current.Type = TT_LineComment;
else
Current.Type = TT_BlockComment;
Current.Type =
Current.TokenText.startswith("/*") ? TT_BlockComment : TT_LineComment;
} else if (Current.is(tok::r_paren)) {
if (rParenEndsCast(Current))
Current.Type = TT_CastRParen;

View File

@ -1035,6 +1035,9 @@ TEST_F(FormatTest, UnderstandsSingleLineComments) {
" // spanning two lines\n"
" x + 3) {\n"
"}"));
verifyNoCrash("/\\\n/");
verifyNoCrash("/\\\n* */");
}
TEST_F(FormatTest, KeepsParameterWithTrailingCommentsOnTheirOwnLine) {