Skip to content

Commit 81d2b65

Browse files
PiJoulesLukacma
authored andcommitted
Revert "Reapply "[clang-format] Annotate ::operator and Foo::operator… (llvm#165038)
… correctly" (llvm#164670)" This reverts commit 50ca1f4. Reverting because this leads to the bug on ToT described in llvm#164866. The original fix addresses an old regression which we'd still like to land eventually. See the discussion in llvm#164670 for more context.
1 parent 7205410 commit 81d2b65

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

clang/lib/Format/TokenAnnotator.cpp

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

3794-
if (Current.isNoneOf(tok::identifier, tok::kw_operator))
3794+
if (!Current.Tok.getIdentifierInfo())
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+
38003806
const auto &Previous = *Prev;
38013807

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

38463852
// Find parentheses of parameter list.
38473853
if (Current.is(tok::kw_operator)) {
3848-
if (Line.startsWith(tok::kw_friend))
3849-
return true;
38503854
if (Previous.Tok.getIdentifierInfo() &&
38513855
Previous.isNoneOf(tok::kw_return, tok::kw_co_return)) {
38523856
return true;

clang/unittests/Format/TokenAnnotatorTest.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1129,11 +1129,6 @@ 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);
11371132
}
11381133

11391134
TEST_F(TokenAnnotatorTest, OverloadedOperatorInTemplate) {

0 commit comments

Comments
 (0)