From: Daniel Jasper Date: Mon, 23 Nov 2015 19:11:45 +0000 (+0000) Subject: clang-format: Re-add code path deleted in r253873 and add missing test. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=fc2939d53f43988f3f179ad2a567721eb720899f;p=clang clang-format: Re-add code path deleted in r253873 and add missing test. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@253900 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp index af87b3c383..b5e7b9a0e6 100644 --- a/lib/Format/TokenAnnotator.cpp +++ b/lib/Format/TokenAnnotator.cpp @@ -1068,6 +1068,15 @@ private: FormatToken *LeftOfParens = Tok.MatchingParen->getPreviousNonComment(); if (LeftOfParens) { + // If there is an opening parenthesis left of the current parentheses, + // look past it as these might be chained casts. + if (LeftOfParens->is(tok::r_paren)) { + if (!LeftOfParens->MatchingParen || + !LeftOfParens->MatchingParen->Previous) + return false; + LeftOfParens = LeftOfParens->MatchingParen->Previous; + } + // If there is an identifier (or with a few exceptions a keyword) right // before the parentheses, this is unlikely to be a cast. if (LeftOfParens->Tok.getIdentifierInfo() && diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index 02f329acfe..176c74bf7e 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -5793,6 +5793,7 @@ TEST_F(FormatTest, FormatsCasts) { verifyFormat("int a = sizeof(int *) + b;"); verifyFormat("int a = alignof(int *) + b;", getGoogleStyle()); verifyFormat("bool b = f(g) && c;"); + verifyFormat("typedef void (*f)(int i) func;"); verifyFormat("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa *foo = (aaaaaaaaaaaaaaaaa *)\n" " bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb;");