This revision was landed with ongoing or failed builds. This revision was automatically updated to reflect the committed changes. Closed by commit rG293e4da32b1d: [clang-format] Correctly indent comment above finalized PPDirective (authored by owenpan).
Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D148200/new/ https://reviews.llvm.org/D148200 Files: clang/lib/Format/TokenAnnotator.cpp clang/unittests/Format/FormatTestComments.cpp Index: clang/unittests/Format/FormatTestComments.cpp =================================================================== --- clang/unittests/Format/FormatTestComments.cpp +++ clang/unittests/Format/FormatTestComments.cpp @@ -1059,6 +1059,13 @@ "#endif\n" " }\n" "}")); + + const StringRef Code("void func() {\n" + " // clang-format off\n" + " #define KV(value) #value, value\n" + " // clang-format on\n" + "}"); + EXPECT_EQ(Code, format(Code)); } TEST_F(FormatTestComments, SplitsLongLinesInComments) { Index: clang/lib/Format/TokenAnnotator.cpp =================================================================== --- clang/lib/Format/TokenAnnotator.cpp +++ clang/lib/Format/TokenAnnotator.cpp @@ -3025,8 +3025,8 @@ // If the comment is currently aligned with the line immediately following // it, that's probably intentional and we should keep it. - if (NextNonCommentLine && Line->isComment() && - NextNonCommentLine->First->NewlinesBefore <= 1 && + if (NextNonCommentLine && !NextNonCommentLine->First->Finalized && + Line->isComment() && NextNonCommentLine->First->NewlinesBefore <= 1 && NextNonCommentLine->First->OriginalColumn == Line->First->OriginalColumn) { const bool PPDirectiveOrImportStmt =
Index: clang/unittests/Format/FormatTestComments.cpp =================================================================== --- clang/unittests/Format/FormatTestComments.cpp +++ clang/unittests/Format/FormatTestComments.cpp @@ -1059,6 +1059,13 @@ "#endif\n" " }\n" "}")); + + const StringRef Code("void func() {\n" + " // clang-format off\n" + " #define KV(value) #value, value\n" + " // clang-format on\n" + "}"); + EXPECT_EQ(Code, format(Code)); } TEST_F(FormatTestComments, SplitsLongLinesInComments) { Index: clang/lib/Format/TokenAnnotator.cpp =================================================================== --- clang/lib/Format/TokenAnnotator.cpp +++ clang/lib/Format/TokenAnnotator.cpp @@ -3025,8 +3025,8 @@ // If the comment is currently aligned with the line immediately following // it, that's probably intentional and we should keep it. - if (NextNonCommentLine && Line->isComment() && - NextNonCommentLine->First->NewlinesBefore <= 1 && + if (NextNonCommentLine && !NextNonCommentLine->First->Finalized && + Line->isComment() && NextNonCommentLine->First->NewlinesBefore <= 1 && NextNonCommentLine->First->OriginalColumn == Line->First->OriginalColumn) { const bool PPDirectiveOrImportStmt =
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits