diff options
-rw-r--r-- | clang/lib/Format/ContinuationIndenter.cpp | 2 | ||||
-rw-r--r-- | clang/lib/Format/TokenAnnotator.cpp | 21 | ||||
-rw-r--r-- | clang/unittests/Format/FormatTest.cpp | 4 |
3 files changed, 20 insertions, 7 deletions
diff --git a/clang/lib/Format/ContinuationIndenter.cpp b/clang/lib/Format/ContinuationIndenter.cpp index b65c0e0664c..1e2946f0b01 100644 --- a/clang/lib/Format/ContinuationIndenter.cpp +++ b/clang/lib/Format/ContinuationIndenter.cpp @@ -250,7 +250,7 @@ bool ContinuationIndenter::mustBreak(const LineState &State) { // If the return type spans multiple lines, wrap before the function name. if ((Current.is(TT_FunctionDeclarationName) || (Current.is(tok::kw_operator) && !Previous.is(tok::coloncolon))) && - State.Stack.back().BreakBeforeParameter) + !Previous.is(tok::kw_template) && State.Stack.back().BreakBeforeParameter) return true; if (startsSegmentOfBuilderTypeCall(Current) && diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index 371c6a3a830..2089d9d3165 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -42,8 +42,21 @@ public: private: bool parseAngle() { - if (!CurrentToken) + if (!CurrentToken || !CurrentToken->Previous) + return false; + if (NonTemplateLess.count(CurrentToken->Previous)) return false; + + const FormatToken& Previous = *CurrentToken->Previous; + if (Previous.Previous) { + if (Previous.Previous->Tok.isLiteral()) + return false; + if (Previous.Previous->is(tok::r_paren) && Contexts.size() > 1 && + (!Previous.Previous->MatchingParen || + !Previous.Previous->MatchingParen->is(TT_OverloadedOperatorLParen))) + return false; + } + FormatToken *Left = CurrentToken->Previous; Left->ParentBracket = Contexts.back().ContextKind; ScopedContextCreator ContextCreator(*this, tok::less, 10); @@ -550,11 +563,7 @@ private: return false; break; case tok::less: - if (!NonTemplateLess.count(Tok) && - (!Tok->Previous || - (!Tok->Previous->Tok.isLiteral() && - !(Tok->Previous->is(tok::r_paren) && Contexts.size() > 1))) && - parseAngle()) { + if (parseAngle()) { Tok->Type = TT_TemplateOpener; } else { Tok->Type = TT_BinaryOperator; diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index e03a484f290..0db5d9c89a1 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -5394,6 +5394,10 @@ TEST_F(FormatTest, UnderstandsTemplateParameters) { verifyFormat("struct A<std::enable_if<sizeof(T2) ? sizeof(int32) : " "sizeof(char)>::type>;"); verifyFormat("template <class T> struct S<std::is_arithmetic<T>{}> {};"); + verifyFormat("f(a.operator()<A>());"); + verifyFormat("f(aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n" + " .template operator()<A>());", + getLLVMStyleWithColumns(35)); // Not template parameters. verifyFormat("return a < b && c > d;"); |