Do not consider comments when adjusting to local indent style.

Before (when only reformatting "int b"):
int a; // comment
       // comment
       int b;

After:
int a; // comment
       // comment
int b;

This also fixes llvm.org/PR15433.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@177524 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Daniel Jasper 2013-03-20 14:31:47 +00:00
Родитель 64f092865c
Коммит 83a90e5e65
2 изменённых файлов: 9 добавлений и 1 удалений

Просмотреть файл

@ -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))

Просмотреть файл

@ -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) {