Эх сурвалжийг харах

clang-format: Improve address-of-operator detection

Before:
  size = sizeof * a;

After:
  size = sizeof *a;

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@191139 91177308-0d34-0410-b5e6-96231b3b80d8
Daniel Jasper 12 жил өмнө
parent
commit
65da8e952d

+ 1 - 1
lib/Format/TokenAnnotator.cpp

@@ -737,7 +737,7 @@ private:
 
 
     if (PrevToken->isOneOf(tok::l_paren, tok::l_square, tok::l_brace,
     if (PrevToken->isOneOf(tok::l_paren, tok::l_square, tok::l_brace,
                            tok::comma, tok::semi, tok::kw_return, tok::colon,
                            tok::comma, tok::semi, tok::kw_return, tok::colon,
-                           tok::equal, tok::kw_delete) ||
+                           tok::equal, tok::kw_delete, tok::kw_sizeof) ||
         PrevToken->Type == TT_BinaryOperator ||
         PrevToken->Type == TT_BinaryOperator ||
         PrevToken->Type == TT_UnaryOperator || PrevToken->Type == TT_CastRParen)
         PrevToken->Type == TT_UnaryOperator || PrevToken->Type == TT_CastRParen)
       return TT_UnaryOperator;
       return TT_UnaryOperator;

+ 1 - 0
unittests/Format/FormatTest.cpp

@@ -3851,6 +3851,7 @@ TEST_F(FormatTest, UnderstandsUsesOfStarAndAmp) {
   verifyIndependentOfContext("if (*b[i])");
   verifyIndependentOfContext("if (*b[i])");
   verifyIndependentOfContext("if (int *a = (&b))");
   verifyIndependentOfContext("if (int *a = (&b))");
   verifyIndependentOfContext("while (int *a = &b)");
   verifyIndependentOfContext("while (int *a = &b)");
+  verifyIndependentOfContext("size = sizeof *a;");
   verifyFormat("void f() {\n"
   verifyFormat("void f() {\n"
                "  for (const int &v : Values) {\n"
                "  for (const int &v : Values) {\n"
                "  }\n"
                "  }\n"