release/20.x: [clang-format] RemoveParentheses shouldn't remove empty parentheses (#138229)

Backport d3506ee573a2aa1403817642ef45f8c0305bb572
This commit is contained in:
Owen Pan 2025-05-02 19:19:39 -07:00 committed by Tom Stellard
parent 5429418cb0
commit a7166c3739
2 changed files with 4 additions and 1 deletions

View File

@ -2581,7 +2581,8 @@ bool UnwrappedLineParser::parseParens(TokenType AmpAmpTokenType) {
if (Prev) {
auto OptionalParens = [&] {
if (MightBeStmtExpr || MightBeFoldExpr || Line->InMacroBody ||
SeenComma || Style.RemoveParentheses == FormatStyle::RPS_Leave) {
SeenComma || Style.RemoveParentheses == FormatStyle::RPS_Leave ||
RParen->getPreviousNonComment() == LParen) {
return false;
}
const bool DoubleParens =

View File

@ -27895,6 +27895,8 @@ TEST_F(FormatTest, RemoveParentheses) {
verifyFormat("return ((... && std::is_convertible_v<TArgsLocal, TArgs>));",
"return (((... && std::is_convertible_v<TArgsLocal, TArgs>)));",
Style);
verifyFormat("MOCK_METHOD(void, Function, (), override);",
"MOCK_METHOD(void, Function, (), (override));", Style);
Style.RemoveParentheses = FormatStyle::RPS_ReturnStatement;
verifyFormat("#define Return0 return (0);", Style);