[PATCH] D131940: [clang-format] Handle comments between access specifier and colon
Owen Pan via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Aug 15 21:50:30 PDT 2022
owenpan created this revision.
owenpan added reviewers: MyDeveloperDay, curdeius, HazardyKnusperkeks.
owenpan added a project: clang-format.
Herald added a project: All.
owenpan requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
Fixes https://github.com/llvm/llvm-project/issues/56740.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D131940
Files:
clang/lib/Format/FormatToken.h
clang/unittests/Format/FormatTest.cpp
Index: clang/unittests/Format/FormatTest.cpp
===================================================================
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -24799,6 +24799,11 @@
" int i;\n"
"};\n",
Style);
+ verifyFormat("class C {\n"
+ " public /* comment */:\n"
+ " int i;\n"
+ "};",
+ Style);
verifyFormat("struct S {\n"
" private:\n"
" class C {\n"
@@ -24827,6 +24832,11 @@
" int i;\n"
"};\n",
Style);
+ verifyFormat("class C {\n"
+ " public /**/:\n"
+ " int i;\n"
+ "};",
+ Style);
}
TEST_F(FormatTest, LimitlessStringsAndComments) {
Index: clang/lib/Format/FormatToken.h
===================================================================
--- clang/lib/Format/FormatToken.h
+++ clang/lib/Format/FormatToken.h
@@ -584,8 +584,12 @@
}
bool isAccessSpecifier(bool ColonRequired = true) const {
- return isOneOf(tok::kw_public, tok::kw_protected, tok::kw_private) &&
- (!ColonRequired || (Next && Next->is(tok::colon)));
+ if (!isOneOf(tok::kw_public, tok::kw_protected, tok::kw_private))
+ return false;
+ if (!ColonRequired)
+ return true;
+ const auto NextNonComment = getNextNonComment();
+ return NextNonComment && NextNonComment->is(tok::colon);
}
bool canBePointerOrReferenceQualifier() const {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D131940.452888.patch
Type: text/x-patch
Size: 1570 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220816/0d948c1b/attachment.bin>
More information about the cfe-commits
mailing list