Skip to content

Commit

Permalink
[clang-format] Annotate ::operator as FunctionDeclarationName (llvm#1…
Browse files Browse the repository at this point in the history
  • Loading branch information
owenca authored Oct 5, 2024
1 parent e5b05a5 commit b5f6689
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
7 changes: 7 additions & 0 deletions clang/lib/Format/TokenAnnotator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3738,6 +3738,13 @@ static bool isFunctionDeclarationName(const LangOptions &LangOpts,

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

if (Prev->is(tok::coloncolon))
Prev = Prev->Previous;

if (!Prev)
return false;

const auto &Previous = *Prev;

if (const auto *PrevPrev = Previous.getPreviousNonComment();
Expand Down
8 changes: 8 additions & 0 deletions clang/unittests/Format/TokenAnnotatorTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1007,6 +1007,14 @@ TEST_F(TokenAnnotatorTest, UnderstandsOverloadedOperators) {
EXPECT_TOKEN(Tokens[6], tok::r_paren, TT_OverloadedOperator);
EXPECT_TOKEN(Tokens[7], tok::l_paren, TT_OverloadedOperatorLParen);
EXPECT_TOKEN(Tokens[9], tok::amp, TT_PointerOrReference);

Tokens = annotate("friend ostream& ::operator<<(ostream& lhs, foo& rhs);");
ASSERT_EQ(Tokens.size(), 17u) << Tokens;
EXPECT_TOKEN(Tokens[4], tok::kw_operator, TT_FunctionDeclarationName);
EXPECT_TOKEN(Tokens[5], tok::lessless, TT_OverloadedOperator);
EXPECT_TOKEN(Tokens[6], tok::l_paren, TT_OverloadedOperatorLParen);
EXPECT_TOKEN(Tokens[8], tok::amp, TT_PointerOrReference);
EXPECT_TOKEN(Tokens[12], tok::amp, TT_PointerOrReference);
}

TEST_F(TokenAnnotatorTest, OverloadedOperatorInTemplate) {
Expand Down

0 comments on commit b5f6689

Please sign in to comment.