Index: clang/lib/Format/TokenAnnotator.cpp =================================================================== --- clang/lib/Format/TokenAnnotator.cpp +++ clang/lib/Format/TokenAnnotator.cpp @@ -260,9 +260,8 @@ } else if (OpeningParen.Previous && (OpeningParen.Previous->isOneOf(tok::kw_static_assert, tok::kw_while, tok::l_paren, - tok::comma) || - OpeningParen.Previous->isIf() || - OpeningParen.Previous->is(TT_BinaryOperator))) { + tok::comma, TT_BinaryOperator) || + OpeningParen.Previous->isIf())) { // static_assert, if and while usually contain expressions. Contexts.back().IsExpression = true; } else if (Style.isJavaScript() && OpeningParen.Previous && @@ -3119,12 +3118,13 @@ Right.is(tok::r_brace) && Right.isNot(BK_Block))) return Style.SpaceInEmptyParentheses; if (Style.SpacesInConditionalStatement) { - if (Left.is(tok::l_paren) && Left.Previous && - isKeywordWithCondition(*Left.Previous)) - return true; - if (Right.is(tok::r_paren) && Right.MatchingParen && - Right.MatchingParen->Previous && - isKeywordWithCondition(*Right.MatchingParen->Previous)) + const FormatToken *LeftParen = nullptr; + if (Left.is(tok::l_paren)) + LeftParen = &Left; + else if (Right.is(tok::r_paren) && Right.MatchingParen) + LeftParen = Right.MatchingParen; + if (LeftParen && LeftParen->Previous && + isKeywordWithCondition(*LeftParen->Previous)) return true; } @@ -3381,10 +3381,8 @@ if (Left.is(tok::semi)) return true; if (Left.isOneOf(tok::pp_elif, tok::kw_for, tok::kw_while, tok::kw_switch, - tok::kw_case, TT_ForEachMacro, TT_ObjCForIn)) - return Style.SpaceBeforeParensOptions.AfterControlStatements || - spaceRequiredBeforeParens(Right); - if (Left.isIf(Line.Type != LT_PreprocessorDirective)) + tok::kw_case, TT_ForEachMacro, TT_ObjCForIn) || + Left.isIf(Line.Type != LT_PreprocessorDirective)) return Style.SpaceBeforeParensOptions.AfterControlStatements || spaceRequiredBeforeParens(Right); @@ -4537,13 +4535,11 @@ // We only break before r_paren if we're in a block indented context. if (Right.is(tok::r_paren)) { - if (Style.AlignAfterOpenBracket == FormatStyle::BAS_BlockIndent) - return Right.MatchingParen && - !(Right.MatchingParen->Previous && - (Right.MatchingParen->Previous->is(tok::kw_for) || - Right.MatchingParen->Previous->isIf())); - - return false; + if (Style.AlignAfterOpenBracket != FormatStyle::BAS_BlockIndent || + !Right.MatchingParen) + return false; + const FormatToken *Previous = Right.MatchingParen->Previous; + return !(Previous && (Previous->is(tok::kw_for) || Previous->isIf())); } // Allow breaking after a trailing annotation, e.g. after a method