Просмотр исходного кода

clang-format: Fix false positive in pointer/reference detection.

Before:
  return options != nullptr &&operator==(*options);

After:
  return options != nullptr && operator==(*options);

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@249501 91177308-0d34-0410-b5e6-96231b3b80d8
Daniel Jasper 10 лет назад
Родитель
Сommit
a164fa507b
2 измененных файлов с 4 добавлено и 1 удалено
  1. 3 1
      lib/Format/TokenAnnotator.cpp
  2. 1 0
      unittests/Format/FormatTest.cpp

+ 3 - 1
lib/Format/TokenAnnotator.cpp

@@ -1158,7 +1158,9 @@ private:
 
     if (NextToken->is(tok::l_square) && NextToken->isNot(TT_LambdaLSquare))
       return TT_PointerOrReference;
-    if (NextToken->isOneOf(tok::kw_operator, tok::comma, tok::semi))
+    if (NextToken->is(tok::kw_operator) && !IsExpression)
+      return TT_PointerOrReference;
+    if (NextToken->isOneOf(tok::comma, tok::semi))
       return TT_PointerOrReference;
 
     if (PrevToken->is(tok::r_paren) && PrevToken->MatchingParen &&

+ 1 - 0
unittests/Format/FormatTest.cpp

@@ -5568,6 +5568,7 @@ TEST_F(FormatTest, UnderstandsUsesOfStarAndAmp) {
   // verifyIndependentOfContext("MACRO(A *a);");
 
   verifyFormat("DatumHandle const *operator->() const { return input_; }");
+  verifyFormat("return options != nullptr && operator==(*options);");
 
   EXPECT_EQ("#define OP(x)                                    \\\n"
             "  ostream &operator<<(ostream &s, const A &a) {  \\\n"