[llvm-branch-commits] [clang] 70e4662 - Revert "[clang-format] Handle object instansiation in if-statements"

Tobias Hieta via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Mon Apr 17 07:26:41 PDT 2023


Author: Tobias Hieta
Date: 2023-04-17T16:26:14+02:00
New Revision: 70e4662aa4993f69a471bc2e274e7002fad74a02

URL: https://github.com/llvm/llvm-project/commit/70e4662aa4993f69a471bc2e274e7002fad74a02
DIFF: https://github.com/llvm/llvm-project/commit/70e4662aa4993f69a471bc2e274e7002fad74a02.diff

LOG: Revert "[clang-format] Handle object instansiation in if-statements"

This reverts commit 70de684d44135b4025d92b2b36ad387cf5ab8b5a.

This causes a regression as described in #61785

(cherry picked from commit 104cd749f5cca609a79303c0dad22bc041b5448a)

Added: 
    

Modified: 
    clang/lib/Format/TokenAnnotator.cpp
    clang/unittests/Format/TokenAnnotatorTest.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp
index ca651eaa94406..464594bf74883 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -399,8 +399,7 @@ class AnnotatingParser {
           FormatToken *Next = CurrentToken->Next;
           if (PrevPrev && PrevPrev->is(tok::identifier) &&
               Prev->isOneOf(tok::star, tok::amp, tok::ampamp) &&
-              CurrentToken->is(tok::identifier) &&
-              !Next->isOneOf(tok::equal, tok::l_brace)) {
+              CurrentToken->is(tok::identifier) && Next->isNot(tok::equal)) {
             Prev->setType(TT_BinaryOperator);
             LookForDecls = false;
           }
@@ -2399,12 +2398,6 @@ class AnnotatingParser {
       return TT_PointerOrReference;
     }
 
-    // if (Class* obj { function() })
-    if (PrevToken->Tok.isAnyIdentifier() && NextToken->Tok.isAnyIdentifier() &&
-        NextToken->Next && NextToken->Next->is(tok::l_brace)) {
-      return TT_PointerOrReference;
-    }
-
     if (PrevToken->endsSequence(tok::r_square, tok::l_square, tok::kw_delete))
       return TT_UnaryOperator;
 

diff  --git a/clang/unittests/Format/TokenAnnotatorTest.cpp b/clang/unittests/Format/TokenAnnotatorTest.cpp
index e44d666206b44..8b41a9f1ca227 100644
--- a/clang/unittests/Format/TokenAnnotatorTest.cpp
+++ b/clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -146,18 +146,6 @@ TEST_F(TokenAnnotatorTest, UnderstandsUsesOfStarAndAmp) {
   EXPECT_TOKEN(Tokens[7], tok::star, TT_UnaryOperator);
   EXPECT_TOKEN(Tokens[12], tok::star, TT_PointerOrReference);
 
-  Tokens = annotate("if (Foo * Bar / Test)");
-  ASSERT_EQ(Tokens.size(), 9u) << Tokens;
-  EXPECT_TOKEN(Tokens[3], tok::star, TT_BinaryOperator);
-
-  Tokens = annotate("if (Class* obj {getObj()})");
-  ASSERT_EQ(Tokens.size(), 12u) << Tokens;
-  EXPECT_TOKEN(Tokens[3], tok::star, TT_PointerOrReference);
-
-  Tokens = annotate("if (Foo* Bar = getObj())");
-  ASSERT_EQ(Tokens.size(), 11u) << Tokens;
-  EXPECT_TOKEN(Tokens[3], tok::star, TT_PointerOrReference);
-
   Tokens = annotate("int f3() { return sizeof(Foo&); }");
   ASSERT_EQ(Tokens.size(), 14u) << Tokens;
   EXPECT_TOKEN(Tokens[9], tok::amp, TT_PointerOrReference);


        


More information about the llvm-branch-commits mailing list