From 676fbe8105eeb6ff4bb2ed261cb212fcfdbe7b63 Mon Sep 17 00:00:00 2001 From: Dimitry Andric Date: Sat, 19 Jan 2019 10:04:05 +0000 Subject: Vendor import of clang trunk r351319 (just before the release_80 branch point): https://llvm.org/svn/llvm-project/cfe/trunk@351319 --- lib/Format/WhitespaceManager.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'lib/Format/WhitespaceManager.cpp') diff --git a/lib/Format/WhitespaceManager.cpp b/lib/Format/WhitespaceManager.cpp index 7070ce03c864..032b1333322d 100644 --- a/lib/Format/WhitespaceManager.cpp +++ b/lib/Format/WhitespaceManager.cpp @@ -90,7 +90,7 @@ const tooling::Replacements &WhitespaceManager::generateReplacements() { if (Changes.empty()) return Replaces; - llvm::sort(Changes.begin(), Changes.end(), Change::IsBeforeInFile(SourceMgr)); + llvm::sort(Changes, Change::IsBeforeInFile(SourceMgr)); calculateLineBreakInformation(); alignConsecutiveDeclarations(); alignConsecutiveAssignments(); @@ -255,8 +255,14 @@ AlignTokenSequence(unsigned Start, unsigned End, unsigned Column, F &&Matches, Changes[ScopeStack.back()].indentAndNestingLevel()) ScopeStack.pop_back(); + // Compare current token to previous non-comment token to ensure whether + // it is in a deeper scope or not. + unsigned PreviousNonComment = i - 1; + while (PreviousNonComment > Start && + Changes[PreviousNonComment].Tok->is(tok::comment)) + PreviousNonComment--; if (i != Start && Changes[i].indentAndNestingLevel() > - Changes[i - 1].indentAndNestingLevel()) + Changes[PreviousNonComment].indentAndNestingLevel()) ScopeStack.push_back(i); bool InsideNestedScope = ScopeStack.size() != 0; -- cgit v1.3