Skip to content

Commit a0c0686

Browse files
committed
[clang-format] Correctly annotate kw_operator in using decls
Fix #136541
1 parent c99ffe5 commit a0c0686

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

clang/lib/Format/TokenAnnotator.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3977,8 +3977,10 @@ void TokenAnnotator::calculateFormattingInformation(AnnotatedLine &Line) const {
39773977
FormatToken *AfterLastAttribute = nullptr;
39783978
FormatToken *ClosingParen = nullptr;
39793979

3980-
for (auto *Tok = FirstNonComment ? FirstNonComment->Next : nullptr; Tok;
3981-
Tok = Tok->Next) {
3980+
for (auto *Tok = FirstNonComment && FirstNonComment->isNot(tok::kw_using)
3981+
? FirstNonComment->Next
3982+
: nullptr;
3983+
Tok; Tok = Tok->Next) {
39823984
if (Tok->is(TT_StartOfName))
39833985
SeenName = true;
39843986
if (Tok->Previous->EndsCppAttributeGroup)

clang/unittests/Format/TokenAnnotatorTest.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1078,6 +1078,11 @@ TEST_F(TokenAnnotatorTest, UnderstandsOverloadedOperators) {
10781078
ASSERT_EQ(Tokens.size(), 11u) << Tokens;
10791079
EXPECT_TOKEN(Tokens[3], tok::identifier, TT_FunctionDeclarationName);
10801080
EXPECT_TOKEN(Tokens[7], tok::l_paren, TT_OverloadedOperatorLParen);
1081+
1082+
Tokens = annotate("using std::operator==;");
1083+
ASSERT_EQ(Tokens.size(), 7u) << Tokens;
1084+
// Not TT_FunctionDeclarationName.
1085+
EXPECT_TOKEN(Tokens[3], tok::kw_operator, TT_Unknown);
10811086
}
10821087

10831088
TEST_F(TokenAnnotatorTest, OverloadedOperatorInTemplate) {

0 commit comments

Comments
 (0)