r225349 - clang-format: Fix unary operator detection.

Daniel Jasper djasper at google.com
Wed Jan 7 04:19:53 PST 2015


Author: djasper
Date: Wed Jan  7 06:19:53 2015
New Revision: 225349

URL: http://llvm.org/viewvc/llvm-project?rev=225349&view=rev
Log:
clang-format: Fix unary operator detection.

Before:
  ** outparam = 1;

After:
  **outparam = 1;

Modified:
    cfe/trunk/lib/Format/TokenAnnotator.cpp
    cfe/trunk/unittests/Format/FormatTest.cpp

Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=225349&r1=225348&r2=225349&view=diff
==============================================================================
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Wed Jan  7 06:19:53 2015
@@ -741,7 +741,8 @@ private:
 
   void modifyContext(const FormatToken &Current) {
     if (Current.getPrecedence() == prec::Assignment &&
-        !Line.First->isOneOf(tok::kw_template, tok::kw_using) &&
+        !Line.First->isOneOf(tok::kw_template, tok::kw_using,
+                             TT_UnaryOperator) &&
         (!Current.Previous || Current.Previous->isNot(tok::kw_operator))) {
       Contexts.back().IsExpression = true;
       for (FormatToken *Previous = Current.Previous;
@@ -752,11 +753,10 @@ private:
           if (!Previous)
             break;
         }
-        if ((Previous->isOneOf(TT_BinaryOperator, TT_UnaryOperator)) &&
+        if (Previous->isOneOf(TT_BinaryOperator, TT_UnaryOperator) &&
             Previous->isOneOf(tok::star, tok::amp) && Previous->Previous &&
-            Previous->Previous->isNot(tok::equal)) {
+            Previous->Previous->isNot(tok::equal))
           Previous->Type = TT_PointerOrReference;
-        }
       }
     } else if (Current.isOneOf(tok::kw_return, tok::kw_throw)) {
       Contexts.back().IsExpression = true;

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=225349&r1=225348&r2=225349&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Wed Jan  7 06:19:53 2015
@@ -5164,6 +5164,7 @@ TEST_F(FormatTest, UnderstandsUsesOfStar
       "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(\n"
       "    aaaaaaaaaaaaaaaaaaaaaaaaaaaa, *aaaaaaaaaaaaaaaaaaaaaaaaaaaaa);");
 
+  verifyGoogleFormat("**outparam = 1;");
   verifyGoogleFormat("int main(int argc, char** argv) {}");
   verifyGoogleFormat("A<int*> a;");
   verifyGoogleFormat("A<int**> a;");





More information about the cfe-commits mailing list