Index: lib/Format/TokenAnnotator.cpp =================================================================== --- lib/Format/TokenAnnotator.cpp +++ lib/Format/TokenAnnotator.cpp @@ -1563,7 +1563,7 @@ (NextToken->is(tok::l_brace) && !NextToken->getNextNonComment())) return TT_PointerOrReference; - if (PrevToken->is(tok::coloncolon)) + if (PrevToken->isOneOf(tok::coloncolon, tok::kw_const)) return TT_PointerOrReference; if (PrevToken->isOneOf(tok::l_paren, tok::l_square, tok::l_brace, @@ -1585,7 +1585,9 @@ FormatToken *TokenBeforeMatchingParen = PrevToken->MatchingParen->getPreviousNonComment(); if (TokenBeforeMatchingParen && - TokenBeforeMatchingParen->isOneOf(tok::kw_typeof, tok::kw_decltype)) + TokenBeforeMatchingParen->isOneOf( + tok::kw_typeof, tok::kw_decltype, TT_FunctionDeclarationName, + TT_StartOfName, TT_OverloadedOperator)) return TT_PointerOrReference; } Index: unittests/Format/FormatTest.cpp =================================================================== --- unittests/Format/FormatTest.cpp +++ unittests/Format/FormatTest.cpp @@ -6156,6 +6156,12 @@ "operator()() && {}"); verifyGoogleFormat("template \n" "auto x() & -> int {}"); + verifyGoogleFormat("template \n" + "auto x() const& noexcept -> bool {}"); + verifyGoogleFormat("template \n" + "void f() &noexcept {}"); + verifyGoogleFormat("template \n" + "auto operator+() &MACRO {}"); } TEST_F(FormatTest, UnderstandsAttributes) {