From 06b83f9d80e1f84d75e8a17e975791234b38bbcd Mon Sep 17 00:00:00 2001 From: Daniel Jasper Date: Tue, 1 Nov 2016 06:23:05 +0000 Subject: [PATCH] clang-format: Fix incorrect binary operator detection. 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 | 2 +- unittests/Format/FormatTest.cpp | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp index 5a0d592a14..129fe84490 100644 --- a/lib/Format/TokenAnnotator.cpp +++ b/lib/Format/TokenAnnotator.cpp @@ -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. diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index b95a29f781..8fe835e579 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -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"); -- 2.40.0