From: Daniel Jasper Date: Mon, 14 Jul 2014 12:38:38 +0000 (+0000) Subject: clang-format: Improve cast detection (fix false positive). X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=2188f45c6af46d00dc9ad082c136dc59e369853b;p=clang clang-format: Improve cast detection (fix false positive). Before: fn(a)(b)+1; After: fn(a)(b) + 1; git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@212935 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp index afa9840619..c150c91e96 100644 --- a/lib/Format/TokenAnnotator.cpp +++ b/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/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index 16959690e0..81b233c2f5 100644 --- a/unittests/Format/FormatTest.cpp +++ b/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; }");