summaryrefslogtreecommitdiffstats
path: root/clang/lib/Format
diff options
context:
space:
mode:
authorDaniel Jasper <djasper@google.com>2015-01-31 07:05:46 +0000
committerDaniel Jasper <djasper@google.com>2015-01-31 07:05:46 +0000
commit30526e79e87f7875a3f9652e4cdfa5a8ca51b701 (patch)
tree80c363163f769a6f39ad41cec9aefd1c37309cb0 /clang/lib/Format
parent9fee8ab4f92d90b5bd05e7f3d651012f855039c9 (diff)
downloadbcm5719-llvm-30526e79e87f7875a3f9652e4cdfa5a8ca51b701.tar.gz
bcm5719-llvm-30526e79e87f7875a3f9652e4cdfa5a8ca51b701.zip
clang-format: Fix incorrect handling of leading whitespace.
Added an assertion that triggered in an existing test case (without observable differences) and fixed the code. llvm-svn: 227677
Diffstat (limited to 'clang/lib/Format')
-rw-r--r--clang/lib/Format/ContinuationIndenter.cpp18
1 files changed, 12 insertions, 6 deletions
diff --git a/clang/lib/Format/ContinuationIndenter.cpp b/clang/lib/Format/ContinuationIndenter.cpp
index c08c138e1b2..fa7c7f1d5d8 100644
--- a/clang/lib/Format/ContinuationIndenter.cpp
+++ b/clang/lib/Format/ContinuationIndenter.cpp
@@ -245,12 +245,18 @@ unsigned ContinuationIndenter::addTokenToState(LineState &State, bool Newline,
(Current.Previous->Tok.getIdentifierInfo() == nullptr ||
Current.Previous->Tok.getIdentifierInfo()->getPPKeywordID() ==
tok::pp_not_keyword))) {
- // FIXME: Is this correct?
- int WhitespaceLength = SourceMgr.getSpellingColumnNumber(
- State.NextToken->WhitespaceRange.getEnd()) -
- SourceMgr.getSpellingColumnNumber(
- State.NextToken->WhitespaceRange.getBegin());
- State.Column += WhitespaceLength;
+ unsigned EndColumn =
+ SourceMgr.getSpellingColumnNumber(Current.WhitespaceRange.getEnd());
+ if (Current.LastNewlineOffset != 0) {
+ // If there is a newline within this token, the final column will solely
+ // determined by the current end column.
+ State.Column = EndColumn;
+ } else {
+ unsigned StartColumn =
+ SourceMgr.getSpellingColumnNumber(Current.WhitespaceRange.getBegin());
+ assert(EndColumn >= StartColumn);
+ State.Column += EndColumn - StartColumn;
+ }
moveStateToNextToken(State, DryRun, /*Newline=*/false);
return 0;
}
OpenPOWER on IntegriCloud