Skip to content

Commit 0387cd0

Browse files
authored
[clang-format] Fix a bug in annotating FunctionAnnotationRParen (#99802)
Fixes #37906.
1 parent a964f2e commit 0387cd0

File tree

3 files changed

+8
-3
lines changed

3 files changed

+8
-3
lines changed

clang/lib/Format/TokenAnnotator.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2467,9 +2467,9 @@ class AnnotatingParser {
24672467
Current.setType(TT_CastRParen);
24682468
if (Current.MatchingParen && Current.Next &&
24692469
!Current.Next->isBinaryOperator() &&
2470-
!Current.Next->isOneOf(tok::semi, tok::colon, tok::l_brace,
2471-
tok::comma, tok::period, tok::arrow,
2472-
tok::coloncolon, tok::kw_noexcept)) {
2470+
!Current.Next->isOneOf(
2471+
tok::semi, tok::colon, tok::l_brace, tok::l_paren, tok::comma,
2472+
tok::period, tok::arrow, tok::coloncolon, tok::kw_noexcept)) {
24732473
if (FormatToken *AfterParen = Current.MatchingParen->Next;
24742474
AfterParen && AfterParen->isNot(tok::caret)) {
24752475
// Make sure this isn't the return type of an Obj-C block declaration.

clang/unittests/Format/FormatTest.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8742,6 +8742,7 @@ TEST_F(FormatTest, FunctionAnnotations) {
87428742
" << abc;");
87438743
verifyFormat("MACRO(abc)::function() // wrap\n"
87448744
" << abc;");
8745+
verifyFormat("FOO(bar)();", getLLVMStyleWithColumns(0));
87458746
}
87468747

87478748
TEST_F(FormatTest, BreaksDesireably) {

clang/unittests/Format/TokenAnnotatorTest.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1930,6 +1930,10 @@ TEST_F(TokenAnnotatorTest, UnderstandsFunctionAnnotations) {
19301930
"A(T) noexcept;");
19311931
ASSERT_EQ(Tokens.size(), 12u) << Tokens;
19321932
EXPECT_TOKEN(Tokens[8], tok::r_paren, TT_Unknown);
1933+
1934+
Tokens = annotate("FOO(bar)();");
1935+
ASSERT_EQ(Tokens.size(), 8u) << Tokens;
1936+
EXPECT_TOKEN(Tokens[3], tok::r_paren, TT_Unknown);
19331937
}
19341938

19351939
TEST_F(TokenAnnotatorTest, UnderstandsFunctionDeclarationNames) {

0 commit comments

Comments
 (0)