[PATCH] D118475: [clang-format] Fix misaligned trailing comments in the presence of an empty block comment.
Marek Kurdej via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Jan 28 13:29:00 PST 2022
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG64df51624f08: [clang-format] Fix misaligned trailing comments in the presence of an empty… (authored by curdeius).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D118475/new/
https://reviews.llvm.org/D118475
Files:
clang/lib/Format/BreakableToken.cpp
clang/unittests/Format/FormatTestComments.cpp
Index: clang/unittests/Format/FormatTestComments.cpp
===================================================================
--- clang/unittests/Format/FormatTestComments.cpp
+++ clang/unittests/Format/FormatTestComments.cpp
@@ -2842,6 +2842,12 @@
"#define FOO_NODELOCAL 4 // Loopback\n\n"
"} // namespace m\n",
getLLVMStyleWithColumns(80)));
+
+ // https://llvm.org/PR53441
+ verifyFormat("/* */ //\n"
+ "int a; //\n");
+ verifyFormat("/**/ //\n"
+ "int a; //\n");
}
TEST_F(FormatTestComments, AlignsBlockCommentDecorations) {
Index: clang/lib/Format/BreakableToken.cpp
===================================================================
--- clang/lib/Format/BreakableToken.cpp
+++ clang/lib/Format/BreakableToken.cpp
@@ -555,7 +555,9 @@
// We never need a decoration when breaking just the trailing "*/" postfix.
bool HasRemainingText = Offset < Content[LineIndex].size();
if (!HasRemainingText) {
- LineLength -= Decoration.size();
+ bool HasDecoration = Lines[LineIndex].ltrim().startswith(Decoration);
+ if (HasDecoration)
+ LineLength -= Decoration.size();
}
}
return LineLength;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D118475.404151.patch
Type: text/x-patch
Size: 1211 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220128/a1545eb9/attachment-0001.bin>
More information about the cfe-commits
mailing list