]> granicus.if.org Git - clang/commitdiff
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(*+[] {});

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@285671 91177308-0d34-0410-b5e6-96231b3b80d8

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

index 5a0d592a1457b5654c4f8354855e6d664423579f..129fe8449043581220d6c74f3294a288b3e0b275 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 b95a29f781c57fe53887082b8c70d3f73ee59580..8fe835e5793e1c40d2c10c09c214e6f850e92cd2 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");