From 57856d3c654d72f37d67e8ac1c6f1438cb434952 Mon Sep 17 00:00:00 2001 From: Daniel Jasper Date: Sat, 31 Jan 2015 07:05:46 +0000 Subject: [PATCH] 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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@227677 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Format/ContinuationIndenter.cpp | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/lib/Format/ContinuationIndenter.cpp b/lib/Format/ContinuationIndenter.cpp index c08c138e1b..fa7c7f1d5d 100644 --- a/lib/Format/ContinuationIndenter.cpp +++ b/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; } -- 2.40.0