Skip to content

[clang-format] Correctly annotate kw_operator in using decls #136545

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions clang/lib/Format/TokenAnnotator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3977,8 +3977,10 @@ void TokenAnnotator::calculateFormattingInformation(AnnotatedLine &Line) const {
FormatToken *AfterLastAttribute = nullptr;
FormatToken *ClosingParen = nullptr;

for (auto *Tok = FirstNonComment ? FirstNonComment->Next : nullptr; Tok;
Tok = Tok->Next) {
for (auto *Tok = FirstNonComment && FirstNonComment->isNot(tok::kw_using)
? FirstNonComment->Next
: nullptr;
Tok; Tok = Tok->Next) {
if (Tok->is(TT_StartOfName))
SeenName = true;
if (Tok->Previous->EndsCppAttributeGroup)
Expand Down
5 changes: 5 additions & 0 deletions clang/unittests/Format/TokenAnnotatorTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1078,6 +1078,11 @@ TEST_F(TokenAnnotatorTest, UnderstandsOverloadedOperators) {
ASSERT_EQ(Tokens.size(), 11u) << Tokens;
EXPECT_TOKEN(Tokens[3], tok::identifier, TT_FunctionDeclarationName);
EXPECT_TOKEN(Tokens[7], tok::l_paren, TT_OverloadedOperatorLParen);

Tokens = annotate("using std::operator==;");
ASSERT_EQ(Tokens.size(), 7u) << Tokens;
// Not TT_FunctionDeclarationName.
EXPECT_TOKEN(Tokens[3], tok::kw_operator, TT_Unknown);
}

TEST_F(TokenAnnotatorTest, OverloadedOperatorInTemplate) {
Expand Down
Loading