diff --git a/clang/lib/Format/ContinuationIndenter.cpp b/clang/lib/Format/ContinuationIndenter.cpp --- a/clang/lib/Format/ContinuationIndenter.cpp +++ b/clang/lib/Format/ContinuationIndenter.cpp @@ -716,8 +716,9 @@ (Previous.is(tok::l_brace) && Previous.isNot(BK_Block) && Style.Cpp11BracedListStyle)) && State.Column > getNewLineColumn(State) && - (!Previous.Previous || !Previous.Previous->isOneOf( - tok::kw_for, tok::kw_while, tok::kw_switch)) && + (!Previous.Previous || + !Previous.Previous->isOneOf(TT_CastRParen, tok::kw_for, tok::kw_while, + tok::kw_switch)) && // Don't do this for simple (no expressions) one-argument function calls // as that feels like needlessly wasting whitespace, e.g.: // diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -5001,7 +5001,13 @@ return false; } const FormatToken *Previous = Right.MatchingParen->Previous; - return !(Previous && (Previous->is(tok::kw_for) || Previous->isIf())); + // Avoid breaking when there is another parens immediately following + // a closing parens, such as in cast operators and indirect function calls. + return !((Previous && (Previous->is(tok::kw_for) || Previous->isIf())) || + (Right.Next && + (Right.Next->is(tok::l_paren) || + (Right.Next->is(tok::r_paren) && + (Right.NestingLevel == 0 || Previous->is(tok::star)))))); } // Allow breaking after a trailing annotation, e.g. after a method