forked from OSchip/llvm-project
[clang-format] Handle comments between access specifier and colon
Fixes #56740. Differential Revision: https://reviews.llvm.org/D131940
This commit is contained in:
parent
ba1fb54821
commit
2185f64771
|
@ -584,8 +584,12 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isAccessSpecifier(bool ColonRequired = true) const {
|
bool isAccessSpecifier(bool ColonRequired = true) const {
|
||||||
return isOneOf(tok::kw_public, tok::kw_protected, tok::kw_private) &&
|
if (!isOneOf(tok::kw_public, tok::kw_protected, tok::kw_private))
|
||||||
(!ColonRequired || (Next && Next->is(tok::colon)));
|
return false;
|
||||||
|
if (!ColonRequired)
|
||||||
|
return true;
|
||||||
|
const auto NextNonComment = getNextNonComment();
|
||||||
|
return NextNonComment && NextNonComment->is(tok::colon);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool canBePointerOrReferenceQualifier() const {
|
bool canBePointerOrReferenceQualifier() const {
|
||||||
|
|
|
@ -24799,6 +24799,11 @@ TEST_F(FormatTest, IndentAccessModifiers) {
|
||||||
" int i;\n"
|
" int i;\n"
|
||||||
"};\n",
|
"};\n",
|
||||||
Style);
|
Style);
|
||||||
|
verifyFormat("class C {\n"
|
||||||
|
" public /* comment */:\n"
|
||||||
|
" int i;\n"
|
||||||
|
"};",
|
||||||
|
Style);
|
||||||
verifyFormat("struct S {\n"
|
verifyFormat("struct S {\n"
|
||||||
" private:\n"
|
" private:\n"
|
||||||
" class C {\n"
|
" class C {\n"
|
||||||
|
@ -24827,6 +24832,11 @@ TEST_F(FormatTest, IndentAccessModifiers) {
|
||||||
" int i;\n"
|
" int i;\n"
|
||||||
"};\n",
|
"};\n",
|
||||||
Style);
|
Style);
|
||||||
|
verifyFormat("class C {\n"
|
||||||
|
" public /**/:\n"
|
||||||
|
" int i;\n"
|
||||||
|
"};",
|
||||||
|
Style);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(FormatTest, LimitlessStringsAndComments) {
|
TEST_F(FormatTest, LimitlessStringsAndComments) {
|
||||||
|
|
Loading…
Reference in New Issue