Loading clang/lib/Format/TokenAnnotator.cpp +2 −2 Original line number Diff line number Diff line Loading @@ -3065,8 +3065,8 @@ void TokenAnnotator::setCommentLineLevels( // If the comment is currently aligned with the line immediately following // it, that's probably intentional and we should keep it. if (NextNonCommentLine && !NextNonCommentLine->First->Finalized && Line->isComment() && NextNonCommentLine->First->NewlinesBefore <= 1 && if (NextNonCommentLine && NextNonCommentLine->First->NewlinesBefore < 2 && Line->isComment() && !isClangFormatOff(Line->First->TokenText) && NextNonCommentLine->First->OriginalColumn == Line->First->OriginalColumn) { const bool PPDirectiveOrImportStmt = Loading clang/unittests/Format/FormatTestComments.cpp +11 −0 Original line number Diff line number Diff line Loading @@ -1069,6 +1069,17 @@ TEST_F(FormatTestComments, KeepsLevelOfCommentBeforePPDirective) { " // clang-format on\n" "}"); verifyNoChange(Code); auto Style = getLLVMStyle(); Style.IndentPPDirectives = FormatStyle::PPDIS_BeforeHash; verifyFormat("#ifdef FOO\n" " // Foo\n" " #define Foo foo\n" "#else\n" " // Bar\n" " #define Bar bar\n" "#endif", Style); } TEST_F(FormatTestComments, SplitsLongLinesInComments) { Loading Loading
clang/lib/Format/TokenAnnotator.cpp +2 −2 Original line number Diff line number Diff line Loading @@ -3065,8 +3065,8 @@ void TokenAnnotator::setCommentLineLevels( // If the comment is currently aligned with the line immediately following // it, that's probably intentional and we should keep it. if (NextNonCommentLine && !NextNonCommentLine->First->Finalized && Line->isComment() && NextNonCommentLine->First->NewlinesBefore <= 1 && if (NextNonCommentLine && NextNonCommentLine->First->NewlinesBefore < 2 && Line->isComment() && !isClangFormatOff(Line->First->TokenText) && NextNonCommentLine->First->OriginalColumn == Line->First->OriginalColumn) { const bool PPDirectiveOrImportStmt = Loading
clang/unittests/Format/FormatTestComments.cpp +11 −0 Original line number Diff line number Diff line Loading @@ -1069,6 +1069,17 @@ TEST_F(FormatTestComments, KeepsLevelOfCommentBeforePPDirective) { " // clang-format on\n" "}"); verifyNoChange(Code); auto Style = getLLVMStyle(); Style.IndentPPDirectives = FormatStyle::PPDIS_BeforeHash; verifyFormat("#ifdef FOO\n" " // Foo\n" " #define Foo foo\n" "#else\n" " // Bar\n" " #define Bar bar\n" "#endif", Style); } TEST_F(FormatTestComments, SplitsLongLinesInComments) { Loading