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 @@ -1964,6 +1964,7 @@ if (PrevToken->isOneOf(tok::l_paren, tok::l_square, tok::l_brace, tok::comma, tok::semi, tok::kw_return, tok::colon, + tok::kw_co_return, tok::kw_co_await, tok::kw_co_yield, tok::equal, tok::kw_delete, tok::kw_sizeof, tok::kw_throw) || PrevToken->isOneOf(TT_BinaryOperator, TT_ConditionalExpr, 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 @@ -7755,6 +7755,15 @@ verifyFormat("co_yield -1;"); verifyFormat("co_return -1;"); + + // Check that * is not treated as a binary operator when we set PointerAlignment + // as PAS_Left after a keyword and not a declaration. + FormatStyle PASLeftStyle = getLLVMStyle(); + PASLeftStyle.PointerAlignment = FormatStyle::PAS_Left; + verifyFormat("co_return *a;", PASLeftStyle); + verifyFormat("co_await *a;", PASLeftStyle); + verifyFormat("co_yield *a", PASLeftStyle); + verifyFormat("return *a;", PASLeftStyle); } TEST_F(FormatTest, DoesNotIndentRelativeToUnaryOperators) {