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 @@ -125,19 +125,18 @@ if (NonTemplateLess.count(CurrentToken->Previous)) return false; - const FormatToken &Previous = *CurrentToken->Previous; // The '<'. - if (Previous.Previous) { - if (Previous.Previous->Tok.isLiteral()) + FormatToken *Left = CurrentToken->Previous; // The '<'. + if (Left->Previous) { + if (Left->Previous->Tok.isLiteral()) return false; - if (Previous.Previous->is(tok::r_paren) && Contexts.size() > 1 && - (!Previous.Previous->MatchingParen || - !Previous.Previous->MatchingParen->is( + if (Left->Previous->is(tok::r_paren) && Contexts.size() > 1 && + (!Left->Previous->MatchingParen || + !Left->Previous->MatchingParen->is( TT_OverloadedOperatorLParen))) { return false; } } - FormatToken *Left = CurrentToken->Previous; Left->ParentBracket = Contexts.back().ContextKind; ScopedContextCreator ContextCreator(*this, tok::less, 12); @@ -185,6 +184,8 @@ } else { CurrentToken->setType(TT_TemplateCloser); } + if (CurrentToken->Next && CurrentToken->Next->Tok.isLiteral()) + return false; next(); return true; } diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -10345,6 +10345,7 @@ // Not template parameters. verifyFormat("return a < b && c > d;"); + verifyFormat("a < 0 ? b : a > 0 ? c : d;"); verifyFormat("void f() {\n" " while (a < b && c > d) {\n" " }\n"