Skip to content

Commit 70e4662

Browse files
committed
Revert "[clang-format] Handle object instansiation in if-statements"
This reverts commit 70de684. This causes a regression as described in #61785 (cherry picked from commit 104cd74)
1 parent bf80902 commit 70e4662

File tree

2 files changed

+1
-20
lines changed

2 files changed

+1
-20
lines changed

clang/lib/Format/TokenAnnotator.cpp

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -399,8 +399,7 @@ class AnnotatingParser {
399399
FormatToken *Next = CurrentToken->Next;
400400
if (PrevPrev && PrevPrev->is(tok::identifier) &&
401401
Prev->isOneOf(tok::star, tok::amp, tok::ampamp) &&
402-
CurrentToken->is(tok::identifier) &&
403-
!Next->isOneOf(tok::equal, tok::l_brace)) {
402+
CurrentToken->is(tok::identifier) && Next->isNot(tok::equal)) {
404403
Prev->setType(TT_BinaryOperator);
405404
LookForDecls = false;
406405
}
@@ -2399,12 +2398,6 @@ class AnnotatingParser {
23992398
return TT_PointerOrReference;
24002399
}
24012400

2402-
// if (Class* obj { function() })
2403-
if (PrevToken->Tok.isAnyIdentifier() && NextToken->Tok.isAnyIdentifier() &&
2404-
NextToken->Next && NextToken->Next->is(tok::l_brace)) {
2405-
return TT_PointerOrReference;
2406-
}
2407-
24082401
if (PrevToken->endsSequence(tok::r_square, tok::l_square, tok::kw_delete))
24092402
return TT_UnaryOperator;
24102403

clang/unittests/Format/TokenAnnotatorTest.cpp

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -146,18 +146,6 @@ TEST_F(TokenAnnotatorTest, UnderstandsUsesOfStarAndAmp) {
146146
EXPECT_TOKEN(Tokens[7], tok::star, TT_UnaryOperator);
147147
EXPECT_TOKEN(Tokens[12], tok::star, TT_PointerOrReference);
148148

149-
Tokens = annotate("if (Foo * Bar / Test)");
150-
ASSERT_EQ(Tokens.size(), 9u) << Tokens;
151-
EXPECT_TOKEN(Tokens[3], tok::star, TT_BinaryOperator);
152-
153-
Tokens = annotate("if (Class* obj {getObj()})");
154-
ASSERT_EQ(Tokens.size(), 12u) << Tokens;
155-
EXPECT_TOKEN(Tokens[3], tok::star, TT_PointerOrReference);
156-
157-
Tokens = annotate("if (Foo* Bar = getObj())");
158-
ASSERT_EQ(Tokens.size(), 11u) << Tokens;
159-
EXPECT_TOKEN(Tokens[3], tok::star, TT_PointerOrReference);
160-
161149
Tokens = annotate("int f3() { return sizeof(Foo&); }");
162150
ASSERT_EQ(Tokens.size(), 14u) << Tokens;
163151
EXPECT_TOKEN(Tokens[9], tok::amp, TT_PointerOrReference);

0 commit comments

Comments
 (0)