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 {
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 {
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits