Skip to content

Commit a7166c3

Browse files
owencatstellar
authored andcommitted
release/20.x: [clang-format] RemoveParentheses shouldn't remove empty parentheses (#138229)
Backport d3506ee
1 parent 5429418 commit a7166c3

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

clang/lib/Format/UnwrappedLineParser.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2581,7 +2581,8 @@ bool UnwrappedLineParser::parseParens(TokenType AmpAmpTokenType) {
25812581
if (Prev) {
25822582
auto OptionalParens = [&] {
25832583
if (MightBeStmtExpr || MightBeFoldExpr || Line->InMacroBody ||
2584-
SeenComma || Style.RemoveParentheses == FormatStyle::RPS_Leave) {
2584+
SeenComma || Style.RemoveParentheses == FormatStyle::RPS_Leave ||
2585+
RParen->getPreviousNonComment() == LParen) {
25852586
return false;
25862587
}
25872588
const bool DoubleParens =

clang/unittests/Format/FormatTest.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27895,6 +27895,8 @@ TEST_F(FormatTest, RemoveParentheses) {
2789527895
verifyFormat("return ((... && std::is_convertible_v<TArgsLocal, TArgs>));",
2789627896
"return (((... && std::is_convertible_v<TArgsLocal, TArgs>)));",
2789727897
Style);
27898+
verifyFormat("MOCK_METHOD(void, Function, (), override);",
27899+
"MOCK_METHOD(void, Function, (), (override));", Style);
2789827900

2789927901
Style.RemoveParentheses = FormatStyle::RPS_ReturnStatement;
2790027902
verifyFormat("#define Return0 return (0);", Style);

0 commit comments

Comments
 (0)