summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Jasper <djasper@google.com>2015-11-23 19:11:45 +0000
committerDaniel Jasper <djasper@google.com>2015-11-23 19:11:45 +0000
commit8e8b4fb678016640be0284f6aa73b8806fb76aec (patch)
treed8dad79b1cfbe12ebdfb6f5796e41d267091c7ec
parenta96925322b9c71003c3ad7be3175d2e3dc64e1ec (diff)
downloadbcm5719-llvm-8e8b4fb678016640be0284f6aa73b8806fb76aec.tar.gz
bcm5719-llvm-8e8b4fb678016640be0284f6aa73b8806fb76aec.zip
clang-format: Re-add code path deleted in r253873 and add missing test.
llvm-svn: 253900
-rw-r--r--clang/lib/Format/TokenAnnotator.cpp9
-rw-r--r--clang/unittests/Format/FormatTest.cpp1
2 files changed, 10 insertions, 0 deletions
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp
index af87b3c3832..b5e7b9a0e65 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/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/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index 02f329acfe5..176c74bf7ee 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/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<int>) && c;");
+ verifyFormat("typedef void (*f)(int i) func;");
verifyFormat("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa *foo = (aaaaaaaaaaaaaaaaa *)\n"
" bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb;");
OpenPOWER on IntegriCloud