Skip to content

Commit c99ffe5

Browse files
authored
[clang-format] Fix a bug in FormatToken::isObjCAccessSpecifier() (#136109)
Fix #136092
1 parent 5e430af commit c99ffe5

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

clang/lib/Format/FormatToken.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -706,8 +706,9 @@ struct FormatToken {
706706
[[nodiscard]] bool isTypeOrIdentifier(const LangOptions &LangOpts) const;
707707

708708
bool isObjCAccessSpecifier() const {
709-
return Next && Next->isOneOf(tok::objc_public, tok::objc_protected,
710-
tok::objc_package, tok::objc_private);
709+
return is(tok::at) && Next &&
710+
Next->isOneOf(tok::objc_public, tok::objc_protected,
711+
tok::objc_package, tok::objc_private);
711712
}
712713

713714
/// Returns whether \p Tok is ([{ or an opening < of a template or in

clang/unittests/Format/TokenAnnotatorTest.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3963,6 +3963,12 @@ TEST_F(TokenAnnotatorTest, UTF8StringLiteral) {
39633963
EXPECT_TOKEN(Tokens[1], tok::utf8_string_literal, TT_Unknown);
39643964
}
39653965

3966+
TEST_F(TokenAnnotatorTest, IdentifierPackage) {
3967+
auto Tokens = annotate("auto package;");
3968+
ASSERT_EQ(Tokens.size(), 4u) << Tokens;
3969+
EXPECT_FALSE(Tokens[0]->isObjCAccessSpecifier());
3970+
}
3971+
39663972
} // namespace
39673973
} // namespace format
39683974
} // namespace clang

0 commit comments

Comments
 (0)