diff options
-rw-r--r-- | lib/Format/TokenAnnotator.cpp | 19 | ||||
-rw-r--r-- | unittests/Format/FormatTest.cpp | 1 |
2 files changed, 11 insertions, 9 deletions
diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp index ececc7c98a..d2e19af56f 100644 --- a/lib/Format/TokenAnnotator.cpp +++ b/lib/Format/TokenAnnotator.cpp @@ -578,15 +578,16 @@ private: Current.Type = TT_LineComment; else Current.Type = TT_BlockComment; - } else if (Current.is(tok::r_paren) && - (Current.Parent->Type == TT_PointerOrReference || - Current.Parent->Type == TT_TemplateCloser) && - (Current.Children.empty() || - (Current.Children[0].isNot(tok::equal) && - Current.Children[0].isNot(tok::semi) && - Current.Children[0].isNot(tok::l_brace)))) { - // FIXME: We need to get smarter and understand more cases of casts. - Current.Type = TT_CastRParen; + } else if (Current.is(tok::r_paren)) { + bool ParensNotExpr = Current.Parent->Type == TT_PointerOrReference || + Current.Parent->Type == TT_TemplateCloser; + bool ParensCouldEndDecl = + !Current.Children.empty() && (Current.Children[0].is(tok::equal) || + Current.Children[0].is(tok::semi) || + Current.Children[0].is(tok::l_brace)); + if (ParensNotExpr && !ParensCouldEndDecl) + // FIXME: We need to get smarter and understand more cases of casts. + Current.Type = TT_CastRParen; } else if (Current.is(tok::at) && Current.Children.size()) { switch (Current.Children[0].FormatTok.Tok.getObjCKeywordID()) { case tok::objc_interface: diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index f2ccdb0022..a91d325b51 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -1723,6 +1723,7 @@ TEST_F(FormatTest, FormatsCasts) { // These are not casts. verifyFormat("void f(int *) {}"); + verifyFormat("f(foo)[4];"); verifyFormat("void f(int *);"); verifyFormat("void f(int *) = 0;"); verifyFormat("void f(SmallVector<int>) {}"); |