Skip to content

Commit d3506ee

Browse files
authored
[clang-format] RemoveParentheses shouldn't remove empty parentheses (#138229)
Fix #138124
1 parent fba68b4 commit d3506ee

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

clang/lib/Format/UnwrappedLineParser.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -2599,7 +2599,8 @@ bool UnwrappedLineParser::parseParens(TokenType AmpAmpTokenType) {
25992599
if (Prev) {
26002600
auto OptionalParens = [&] {
26012601
if (MightBeStmtExpr || MightBeFoldExpr || Line->InMacroBody ||
2602-
SeenComma || Style.RemoveParentheses == FormatStyle::RPS_Leave) {
2602+
SeenComma || Style.RemoveParentheses == FormatStyle::RPS_Leave ||
2603+
RParen->getPreviousNonComment() == LParen) {
26032604
return false;
26042605
}
26052606
const bool DoubleParens =

clang/unittests/Format/FormatTest.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -28453,6 +28453,8 @@ TEST_F(FormatTest, RemoveParentheses) {
2845328453
verifyFormat("return ((... && std::is_convertible_v<TArgsLocal, TArgs>));",
2845428454
"return (((... && std::is_convertible_v<TArgsLocal, TArgs>)));",
2845528455
Style);
28456+
verifyFormat("MOCK_METHOD(void, Function, (), override);",
28457+
"MOCK_METHOD(void, Function, (), (override));", Style);
2845628458

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

0 commit comments

Comments
 (0)