Skip to content

Commit cc4d64d

Browse files
owencadvbuka
authored andcommitted
Reapply "Reapply "[clang-format] Annotate ::operator and Foo::operator… (llvm#165038)
This reverts commit bd27abc. See llvm#164670 (comment)
1 parent 21f467e commit cc4d64d

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

clang/lib/Format/TokenAnnotator.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3791,18 +3791,12 @@ static bool isFunctionDeclarationName(const LangOptions &LangOpts,
37913791
if (Current.is(TT_FunctionDeclarationName))
37923792
return true;
37933793

3794-
if (!Current.Tok.getIdentifierInfo())
3794+
if (Current.isNoneOf(tok::identifier, tok::kw_operator))
37953795
return false;
37963796

37973797
const auto *Prev = Current.getPreviousNonComment();
37983798
assert(Prev);
37993799

3800-
if (Prev->is(tok::coloncolon))
3801-
Prev = Prev->Previous;
3802-
3803-
if (!Prev)
3804-
return false;
3805-
38063800
const auto &Previous = *Prev;
38073801

38083802
if (const auto *PrevPrev = Previous.getPreviousNonComment();
@@ -3851,6 +3845,8 @@ static bool isFunctionDeclarationName(const LangOptions &LangOpts,
38513845

38523846
// Find parentheses of parameter list.
38533847
if (Current.is(tok::kw_operator)) {
3848+
if (Line.startsWith(tok::kw_friend))
3849+
return true;
38543850
if (Previous.Tok.getIdentifierInfo() &&
38553851
Previous.isNoneOf(tok::kw_return, tok::kw_co_return)) {
38563852
return true;

clang/unittests/Format/TokenAnnotatorTest.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1129,6 +1129,11 @@ TEST_F(TokenAnnotatorTest, UnderstandsOverloadedOperators) {
11291129
ASSERT_EQ(Tokens.size(), 7u) << Tokens;
11301130
// Not TT_FunctionDeclarationName.
11311131
EXPECT_TOKEN(Tokens[3], tok::kw_operator, TT_Unknown);
1132+
1133+
Tokens = annotate("SomeAPI::operator()();");
1134+
ASSERT_EQ(Tokens.size(), 9u) << Tokens;
1135+
// Not TT_FunctionDeclarationName.
1136+
EXPECT_TOKEN(Tokens[2], tok::kw_operator, TT_Unknown);
11321137
}
11331138

11341139
TEST_F(TokenAnnotatorTest, OverloadedOperatorInTemplate) {

0 commit comments

Comments
 (0)