summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Jasper <djasper@google.com>2014-07-14 12:38:38 +0000
committerDaniel Jasper <djasper@google.com>2014-07-14 12:38:38 +0000
commit3064620d0d5bd14ec7faf1bec0ec49f650981e85 (patch)
treeb06a5667d98f98f4478ca826caeb6dd3a27b3852
parent6a931f507a9927158e3d84d780ee00db76efb599 (diff)
downloadbcm5719-llvm-3064620d0d5bd14ec7faf1bec0ec49f650981e85.tar.gz
bcm5719-llvm-3064620d0d5bd14ec7faf1bec0ec49f650981e85.zip
clang-format: Improve cast detection (fix false positive).
Before: fn(a)(b)+1; After: fn(a)(b) + 1; llvm-svn: 212935
-rw-r--r--clang/lib/Format/TokenAnnotator.cpp2
-rw-r--r--clang/unittests/Format/FormatTest.cpp1
2 files changed, 3 insertions, 0 deletions
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp
index afa9840619e..c150c91e96a 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -841,6 +841,8 @@ private:
FormatToken *LeftOfParens = nullptr;
if (Tok.MatchingParen)
LeftOfParens = Tok.MatchingParen->getPreviousNonComment();
+ if (LeftOfParens && LeftOfParens->is(tok::r_paren))
+ return false;
bool IsCast = false;
bool ParensAreEmpty = Tok.Previous == Tok.MatchingParen;
bool ParensAreType = !Tok.Previous ||
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index 16959690e00..81b233c2f54 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -4975,6 +4975,7 @@ TEST_F(FormatTest, FormatsCasts) {
verifyFormat("return (my_int)aaa;");
verifyFormat("#define x ((int)-1)");
verifyFormat("#define p(q) ((int *)&q)");
+ verifyFormat("fn(a)(b) + 1;");
verifyFormat("void f() { my_int a = (my_int)*b; }");
verifyFormat("void f() { return P ? (my_int)*P : (my_int)0; }");
OpenPOWER on IntegriCloud