clang-format: Fix incorrect binary operator detection.
authorDaniel Jasper <djasper@google.com>
Tue, 1 Nov 2016 06:23:05 +0000 (06:23 +0000)
committerDaniel Jasper <djasper@google.com>
Tue, 1 Nov 2016 06:23:05 +0000 (06:23 +0000)
Before:
  int x = f(* + [] {});

After:
  int x = f(*+[] {});

llvm-svn: 285671

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

index 5a0d592..129fe84 100644 (file)
@@ -1310,7 +1310,7 @@ private:
 
   TokenType determinePlusMinusCaretUsage(const FormatToken &Tok) {
     const FormatToken *PrevToken = Tok.getPreviousNonComment();
-    if (!PrevToken || PrevToken->is(TT_CastRParen))
+    if (!PrevToken || PrevToken->isOneOf(TT_CastRParen, TT_UnaryOperator))
       return TT_UnaryOperator;
 
     // Use heuristics to recognize unary operators.
index b95a29f..8fe835e 100644 (file)
@@ -10954,6 +10954,7 @@ TEST_F(FormatTest, FormatsLambdas) {
   verifyFormat("int c = [&a, &a, a] { [=, a, b, &c] { return b++; }(); }();\n");
   verifyFormat("auto c = {[&a, &a, a] { [=, a, b, &c] { return b++; }(); }}\n");
   verifyFormat("auto c = {[&a, &a, a] { [=, a, b, &c] {}(); }}\n");
+  verifyFormat("int x = f(*+[] {});");
   verifyFormat("void f() {\n"
                "  other(x.begin(), x.end(), [&](int, int) { return 1; });\n"
                "}\n");