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

Tom Stellard via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Fri May 9 13:46:18 PDT 2025


Author: Owen Pan
Date: 2025-05-09T13:45:23-07:00
New Revision: a7166c37394612a58bcd237cefbb8fce7424e747

URL: https://github.com/llvm/llvm-project/commit/a7166c37394612a58bcd237cefbb8fce7424e747
DIFF: https://github.com/llvm/llvm-project/commit/a7166c37394612a58bcd237cefbb8fce7424e747.diff

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

Backport d3506ee573a2aa1403817642ef45f8c0305bb572

Added: 
    

Modified: 
    clang/lib/Format/UnwrappedLineParser.cpp
    clang/unittests/Format/FormatTest.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp
index 2b348c926294e..c3ffabce15ec8 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -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 =

diff  --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index bf3eff129efd5..49e1fde1d9ccf 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -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);


        


More information about the llvm-branch-commits mailing list