diff options
| -rw-r--r-- | clang/lib/Format/Format.cpp | 3 | ||||
| -rw-r--r-- | clang/unittests/Format/FormatTest.cpp | 7 |
2 files changed, 9 insertions, 1 deletions
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp index 1a7dbe09365..b1005b5de6c 100644 --- a/clang/lib/Format/Format.cpp +++ b/clang/lib/Format/Format.cpp @@ -1324,7 +1324,8 @@ public: unsigned LevelIndent = Indent; if (static_cast<int>(LevelIndent) - Offset >= 0) LevelIndent -= Offset; - IndentForLevel[TheLine.Level] = LevelIndent; + if (TheLine.First.isNot(tok::comment)) + IndentForLevel[TheLine.Level] = LevelIndent; // Remove trailing whitespace of the previous line if it was touched. if (PreviousLineWasTouched || touchesEmptyLineBefore(TheLine)) diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index 7f9cecb031e..40f09539e7a 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -3279,6 +3279,13 @@ TEST_F(FormatTest, ReformatRegionAdjustsIndent) { format("void f() {}\n" "void g() {}", 13, 0, getLLVMStyle())); + EXPECT_EQ("int a; // comment\n" + " // line 2\n" + "int b;", + format("int a; // comment\n" + " // line 2\n" + " int b;", + 35, 0, getLLVMStyle())); } TEST_F(FormatTest, BreakStringLiterals) { |

