Skip to content

Commit

Permalink
[clang-format] Fix a misannotation of redundant r_paren as CastRParen (
Browse files Browse the repository at this point in the history
  • Loading branch information
owenca authored Aug 25, 2024
1 parent 3ef64f7 commit 6bc225e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
2 changes: 2 additions & 0 deletions clang/lib/Format/TokenAnnotator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2875,6 +2875,8 @@ class AnnotatingParser {
// Search for unexpected tokens.
for (auto *Prev = BeforeRParen; Prev != LParen; Prev = Prev->Previous) {
if (Prev->is(tok::r_paren)) {
if (Prev->is(TT_CastRParen))
return false;
Prev = Prev->MatchingParen;
if (!Prev)
return false;
Expand Down
6 changes: 6 additions & 0 deletions clang/unittests/Format/TokenAnnotatorTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -747,6 +747,12 @@ TEST_F(TokenAnnotatorTest, UnderstandsCasts) {
EXPECT_TOKEN(Tokens[9], tok::r_paren, TT_CastRParen);
EXPECT_TOKEN(Tokens[10], tok::amp, TT_UnaryOperator);

Tokens = annotate("int result = ((int)a) - b;");
ASSERT_EQ(Tokens.size(), 13u) << Tokens;
EXPECT_TOKEN(Tokens[6], tok::r_paren, TT_CastRParen);
EXPECT_TOKEN(Tokens[8], tok::r_paren, TT_Unknown);
EXPECT_TOKEN(Tokens[9], tok::minus, TT_BinaryOperator);

auto Style = getLLVMStyle();
Style.TypeNames.push_back("Foo");
Tokens = annotate("#define FOO(bar) foo((Foo)&bar)", Style);
Expand Down

0 comments on commit 6bc225e

Please sign in to comment.