[PATCH] D148200: [clang-format] Correctly indent comment above finalized PPDirective
Owen Pan via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Apr 14 13:59:05 PDT 2023
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 =
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D148200.513740.patch
Type: text/x-patch
Size: 1424 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230414/eb0fedd2/attachment.bin>
More information about the cfe-commits
mailing list