diff options
author | Ilya Biryukov <ibiryukov@google.com> | 2018-08-01 15:32:56 +0000 |
---|---|---|
committer | Ilya Biryukov <ibiryukov@google.com> | 2018-08-01 15:32:56 +0000 |
commit | fe1098c84823b8eac46b0bfffc5f5788b6c26d1a (patch) | |
tree | 0951b151bb3d53019e3ddf47a52f2ebf0192efa6 /lib/Format | |
parent | 2f6d0b8d50fbb0638b173d6d9da0dae804c82fb2 (diff) | |
download | clang-fe1098c84823b8eac46b0bfffc5f5788b6c26d1a.tar.gz |
[Format] Fix for bug 35641
Summary:
Bug was caused due to comments at the start of scope. For a code like:
```
int func() { //
int b;
int c;
}
```
the comment at the first line gets IndentAndNestingLevel (1,1) whereas
the following declarations get only (0,1) which prevents them from insertion
of a new scope. So, I changed the AlignTokenSequence to look at previous
*non-comment* token when deciding whether to introduce a new scope into
stack or not.
Patch by Kadir Cetinkaya!
Reviewers: rsmith, djasper
Reviewed By: djasper
Subscribers: lebedev.ri, cfe-commits, klimek
Tags: #clang
Differential Revision: https://reviews.llvm.org/D43303
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@338578 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Format')
-rw-r--r-- | lib/Format/WhitespaceManager.cpp | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/lib/Format/WhitespaceManager.cpp b/lib/Format/WhitespaceManager.cpp index 7070ce03c8..a88c22f4e9 100644 --- a/lib/Format/WhitespaceManager.cpp +++ b/lib/Format/WhitespaceManager.cpp @@ -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; |