forked from OSchip/llvm-project
clang-format: Fix crasher.
Caused by unknown tokens (e.g. "\n") not properly updating the state. Example: const char* c = STRINGIFY( \na : b); llvm-svn: 203645
This commit is contained in:
parent
1da3512166
commit
da353cd5f1
|
@ -227,8 +227,8 @@ unsigned ContinuationIndenter::addTokenToState(LineState &State, bool Newline,
|
|||
State.NextToken->WhitespaceRange.getEnd()) -
|
||||
SourceMgr.getSpellingColumnNumber(
|
||||
State.NextToken->WhitespaceRange.getBegin());
|
||||
State.Column += WhitespaceLength + State.NextToken->ColumnWidth;
|
||||
State.NextToken = State.NextToken->Next;
|
||||
State.Column += WhitespaceLength;
|
||||
moveStateToNextToken(State, DryRun, /*NewLine=*/false);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -349,7 +349,6 @@ unsigned ContinuationIndenter::addTokenOnNewLine(LineState &State,
|
|||
|
||||
Penalty += State.NextToken->SplitPenalty;
|
||||
|
||||
|
||||
// Breaking before the first "<<" is generally not desirable if the LHS is
|
||||
// short. Also always add the penalty if the LHS is split over mutliple lines
|
||||
// to avoid unncessary line breaks that just work around this penalty.
|
||||
|
|
|
@ -2024,6 +2024,10 @@ TEST_F(FormatTest, DoesntRemoveUnknownTokens) {
|
|||
verifyFormat("#define A ''qqq");
|
||||
verifyFormat("#define A `qqq");
|
||||
verifyFormat("f(\"aaaa, bbbb, \"\\\"ccccc\\\"\");");
|
||||
EXPECT_EQ("const char *c = STRINGIFY(\n"
|
||||
"\\na : b);",
|
||||
format("const char * c = STRINGIFY(\n"
|
||||
"\\na : b);"));
|
||||
}
|
||||
|
||||
TEST_F(FormatTest, IndentsPPDirectiveInReducedSpace) {
|
||||
|
|
Loading…
Reference in New Issue