[PATCH] D129892: Fix aligning of trailing comments after comment at the end of a namespace
Danil Sidoruk via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Jul 15 12:09:38 PDT 2022
eoanermine created this revision.
eoanermine added reviewers: owenpan, HazardyKnusperkeks, curdeius, MyDeveloperDay.
eoanermine added projects: clang, clang-format.
Herald added a project: All.
eoanermine requested review of this revision.
Herald added a subscriber: cfe-commits.
- Fix aligning of trailing comments after comment at the end of a namespace
- Add tests for aligning of trailing comments after comment that documents the closing of a namespace
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D129892
Files:
clang/lib/Format/WhitespaceManager.cpp
clang/unittests/Format/FormatTest.cpp
Index: clang/unittests/Format/FormatTest.cpp
===================================================================
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -17458,6 +17458,40 @@
Alignment);
}
+TEST_F(FormatTest, AlignTrailingComments) {
+ FormatStyle Style = getLLVMStyle();
+ EXPECT_EQ(Style.AlignTrailingComments, true);
+
+ verifyFormat("namespace test {\n"
+ "class C;\n"
+ "} // namespace test\n"
+ "// Lorem ipsum dolor sit amet, consectetur adipiscing elit. "
+ "Nullam cursus nunc\n"
+ "// non",
+ Style);
+ verifyFormat("namespace test {\n"
+ "class C;\n"
+ "} // namespace test\n"
+ "// Lorem ipsum dolor sit amet, consectetur adipiscing elit. "
+ "Nullam cursus nunc\n"
+ "// non\n",
+ Style);
+ verifyFormat("namespace test {\n"
+ "class C;\n"
+ "} // namespace test\n"
+ "// Lorem ipsum dolor sit amet, consectetur adipiscing elit. "
+ "Nullam cursus nunc\n"
+ "// non other text",
+ Style);
+ verifyFormat("namespace test {\n"
+ "class C;\n"
+ "} // namespace test\n"
+ "// Lorem ipsum dolor sit amet, consectetur adipiscing elit. "
+ "Nullam cursus nunc\n"
+ "// non other text\n",
+ Style);
+}
+
TEST_F(FormatTest, AlignConsecutiveBitFields) {
FormatStyle Alignment = getLLVMStyle();
Alignment.AlignConsecutiveBitFields.Enabled = true;
Index: clang/lib/Format/WhitespaceManager.cpp
===================================================================
--- clang/lib/Format/WhitespaceManager.cpp
+++ clang/lib/Format/WhitespaceManager.cpp
@@ -966,6 +966,10 @@
unsigned NextColumn = SourceMgr.getSpellingColumnNumber(
Changes[j].OriginalWhitespaceRange.getEnd());
+ // Handle files without newline before the end of file correct
+ if (Changes[j].Tok->is(tok::eof))
+ NextColumn = 1;
+
// The start of the next token was previously aligned with the
// start of this comment.
WasAlignedWithStartOfNextLine =
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D129892.445092.patch
Type: text/x-patch
Size: 2304 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220715/758afe40/attachment.bin>
More information about the cfe-commits
mailing list