diff options
| -rw-r--r-- | clang/lib/Format/WhitespaceManager.cpp | 8 | ||||
| -rw-r--r-- | clang/unittests/Format/FormatTest.cpp | 8 |
2 files changed, 15 insertions, 1 deletions
diff --git a/clang/lib/Format/WhitespaceManager.cpp b/clang/lib/Format/WhitespaceManager.cpp index 7070ce03c86..a88c22f4e96 100644 --- a/clang/lib/Format/WhitespaceManager.cpp +++ b/clang/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; diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index f234e287cf1..2e780e163be 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -9804,6 +9804,14 @@ TEST_F(FormatTest, AlignConsecutiveDeclarations) { "});\n", Alignment); Alignment.PointerAlignment = FormatStyle::PAS_Right; + + // See llvm.org/PR35641 + Alignment.AlignConsecutiveDeclarations = true; + verifyFormat("int func() { //\n" + " int b;\n" + " unsigned c;\n" + "}", + Alignment); } TEST_F(FormatTest, LinuxBraceBreaking) { |

