Skip to content

Commit 2ee8fab

Browse files
committed
Handle comment above PP Directive
1 parent 7039ddc commit 2ee8fab

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

clang/lib/Format/UnwrappedLineFormatter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ class LevelIndentTracker {
6363
if (Line.Level >= IndentForLevel.size())
6464
IndentForLevel.resize(Line.Level + 1, -1);
6565
if (Style.IndentPPDirectives == FormatStyle::PPDIS_Leave &&
66-
Line.InPPDirective) {
66+
(Line.InPPDirective || Line.Type == LT_CommentAbovePPDirective)) {
6767
Indent = Line.InMacroBody
6868
? (Line.Level - Line.PPLevel) * Style.IndentWidth +
6969
AdditionalIndent

clang/unittests/Format/FormatTest.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5585,6 +5585,13 @@ TEST_F(FormatTest, IndentsPPDirectiveWithPPIndentWidth) {
55855585
"}\n"
55865586
" #endif",
55875587
style);
5588+
verifyNoChange("#ifdef foo\n"
5589+
"#else\n"
5590+
"/* This is a comment */\n"
5591+
"#ifdef BAR\n"
5592+
"#endif\n"
5593+
"#endif",
5594+
style);
55885595

55895596
style.IndentWidth = 1;
55905597
style.PPIndentWidth = 4;

0 commit comments

Comments
 (0)