Skip to content

Commit c8603db

Browse files
committed
[clang-format] Fix a bug that misformats Access Specifier after *[]
Fixes llvm#55132. Differential Revision: https://reviews.llvm.org/D124589
1 parent 464c983 commit c8603db

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

clang/lib/Format/UnwrappedLineParser.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2048,6 +2048,11 @@ bool UnwrappedLineParser::tryToParseLambdaIntroducer() {
20482048
nextToken();
20492049
if (FormatTok->is(tok::l_square))
20502050
return false;
2051+
if (FormatTok->is(tok::r_square)) {
2052+
const FormatToken *Next = Tokens->peekNextToken();
2053+
if (Next && Next->is(tok::greater))
2054+
return false;
2055+
}
20512056
parseSquare(/*LambdaIntroducer=*/true);
20522057
return true;
20532058
}

clang/unittests/Format/FormatTest.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3336,6 +3336,14 @@ TEST_F(FormatTest, UnderstandsAccessSpecifiers) {
33363336
verifyFormat("if (public == private)\n");
33373337
verifyFormat("void foo(public, private)");
33383338
verifyFormat("public::foo();");
3339+
3340+
verifyFormat("class A {\n"
3341+
"public:\n"
3342+
" std::unique_ptr<int *[]> b() { return nullptr; }\n"
3343+
"\n"
3344+
"private:\n"
3345+
" int c;\n"
3346+
"};");
33393347
}
33403348

33413349
TEST_F(FormatTest, SeparatesLogicalBlocks) {
@@ -21487,6 +21495,7 @@ TEST_F(FormatTest, FormatsLambdas) {
2148721495
" bar([]() {} // Did not respect SpacesBeforeTrailingComments\n"
2148821496
" );\n"
2148921497
"}");
21498+
verifyFormat("auto k = *[](int *j) { return j; }(&i);");
2149021499

2149121500
// Lambdas created through weird macros.
2149221501
verifyFormat("void f() {\n"

0 commit comments

Comments
 (0)