Author: Björn Schäpers
Date: 2026-10-21T20:53:41+02:00
New Revision: 107253eb689f9b2ad7567f86d965f292b712d57d

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

LOG: [clang-format] Fix UseBreakAfter with casts (#233556)

First check for a new argument, before skipping an inner scope.

Fixes #229473

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index 382f15081ad741..8ca8477a285971 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -4372,15 +4372,13 @@ void 
TokenAnnotator::calculateFormattingInformation(AnnotatedLine &Line) const {
       const auto *RParen = Prev->MatchingParen;
       for (auto *ParamTok = Current; ParamTok && ParamTok != RParen;
            ParamTok = ParamTok->Next) {
-        if (ParamTok->opensScope()) {
-          ParamTok = ParamTok->MatchingParen;
-          continue;
-        }
 
         if (startsNextParameter(*ParamTok, Style)) {
           ParamTok->MustBreakBefore = true;
           ParamTok->CanBreakBefore = true;
         }
+        if (ParamTok->opensScope())
+          ParamTok = ParamTok->MatchingParen;
       }
     }
 

diff  --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index 3a680fe9a6a725..8a2c54ec5999df 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -8307,6 +8307,13 @@ TEST_F(FormatTest, BreakFunctionDefinitionParameters) {
                "             3};\n"
                "}",
                Style);
+  verifyFormat("int main() {\n"
+               "  MyFunc(&a,\n"
+               "         &b,\n"
+               "         (uint8_t *)c,\n"
+               "         d);\n"
+               "}",
+               Style);
 }
 
 TEST_F(FormatTest, BreakBeforeInlineASMColon) {


        
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to