Improve understanding of unary operators.
authorDaniel Jasper <djasper@google.com>
Wed, 16 Jan 2013 16:04:06 +0000 (16:04 +0000)
committerDaniel Jasper <djasper@google.com>
Wed, 16 Jan 2013 16:04:06 +0000 (16:04 +0000)
Before: int x = ** a;
After:  int x = **a;
llvm-svn: 172619

clang/lib/Format/Format.cpp
clang/unittests/Format/FormatTest.cpp

index 4be41da..ebf493c 100644 (file)
@@ -1180,7 +1180,7 @@ private:
         PrevToken->is(tok::l_brace) || PrevToken->is(tok::comma) ||
         PrevToken->is(tok::kw_return) || PrevToken->is(tok::colon) ||
         PrevToken->Type == TT_BinaryOperator ||
-        PrevToken->Type == TT_CastRParen)
+        PrevToken->Type == TT_UnaryOperator || PrevToken->Type == TT_CastRParen)
       return TT_UnaryOperator;
 
     if (PrevToken->FormatTok.Tok.isLiteral() || PrevToken->is(tok::r_paren) ||
index 7d8ed14..6dd7cad 100644 (file)
@@ -1167,6 +1167,11 @@ TEST_F(FormatTest, UnderstandsUsesOfStarAndAmp) {
   verifyGoogleFormat("A<int**, int**> a;");
   verifyGoogleFormat("f(b ? *c : *d);");
   verifyGoogleFormat("int a = b ? *c : *d;");
+  verifyGoogleFormat("Type* t = **x;");
+  verifyGoogleFormat("Type* t = *++*x;");
+  verifyGoogleFormat("*++*x;");
+  verifyGoogleFormat("Type* t = const_cast<T*>(&*x);");
+  verifyGoogleFormat("Type* t = x++ * y;");
 
   verifyFormat("a = *(x + y);");
   verifyFormat("a = &(x + y);");