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 @@ -1801,14 +1801,16 @@ return TT_BinaryOperator; // "&&(" is quite unlikely to be two successive unary "&". - if (Tok.is(tok::ampamp) && NextToken && NextToken->is(tok::l_paren)) + if (Tok.is(tok::ampamp) && NextToken->is(tok::l_paren)) return TT_BinaryOperator; // This catches some cases where evaluation order is used as control flow: // aaa && aaa->f(); - const FormatToken *NextNextToken = NextToken->getNextNonComment(); - if (NextNextToken && NextNextToken->is(tok::arrow)) - return TT_BinaryOperator; + if (NextToken->Tok.isAnyIdentifier()) { + const FormatToken *NextNextToken = NextToken->getNextNonComment(); + if (NextNextToken && NextNextToken->is(tok::arrow)) + return TT_BinaryOperator; + } // It is very unlikely that we are going to find a pointer or reference type // definition on the RHS of an assignment. 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 @@ -7407,6 +7407,9 @@ verifyFormat("typedef typeof(int(int, int))* MyFuncPtr;", Left); verifyFormat("[](const decltype(*a)* ptr) {}", Left); verifyFormat("typedef typeof /*comment*/ (int(int, int))* MyFuncPtr;", Left); + verifyFormat("auto x(A&&, B&&, C&&) -> D;", Left); + verifyFormat("auto x = [](A&&, B&&, C&&) -> D {};", Left); + verifyFormat("template X(T&&, T&&, T&&) -> X;", Left); verifyIndependentOfContext("a = *(x + y);"); verifyIndependentOfContext("a = &(x + y);");