[clang] ae614a9 - [clang-format] Preserve enum initializer continuation indentation (#223435)

via cfe-commits cfe-commits at lists.llvm.org
Fri Sep 25 13:57:38 PDT 2026


Author: Aaron
Date: 2026-09-25T22:57:30+02:00
New Revision: ae614a9564425ab206940f2b91607b1d77826068

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

LOG: [clang-format] Preserve enum initializer continuation indentation (#223435)

Fixes #223011

Enum assignment operators are annotated as TT_EnumEqual so they can be
aligned independently in #194154. However, this means
ContinuationIndenter no longer recognizes a wrapped enum `=` as
TT_BinaryOperator. As a result, it may force unnecessary breaks within
the RHS binary expression.

Co-authored-by: Aaron Saw Min Sern <aaron at aaronsms.com>

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/clang/lib/Format/ContinuationIndenter.cpp b/clang/lib/Format/ContinuationIndenter.cpp
index aa264c1487bce8..f210bdecdee644 100644
--- a/clang/lib/Format/ContinuationIndenter.cpp
+++ b/clang/lib/Format/ContinuationIndenter.cpp
@@ -1387,8 +1387,8 @@ unsigned ContinuationIndenter::addTokenOnNewLine(LineState &State,
         !PreviousNonComment->ClosesRequiresClause) ||
        Current.NestingLevel != 0) &&
       PreviousNonComment->isNoneOf(
-          TT_BinaryOperator, TT_FunctionAnnotationRParen, TT_JavaAnnotation,
-          TT_LeadingJavaAnnotation) &&
+          TT_BinaryOperator, TT_EnumEqual, TT_FunctionAnnotationRParen,
+          TT_JavaAnnotation, TT_LeadingJavaAnnotation) &&
       Current.isNot(TT_BinaryOperator) && !PreviousNonComment->opensScope() &&
       // We don't want to enforce line breaks for subsequent arguments just
       // because we have been forced to break before a lambda body.

diff  --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index 5aed37aa56d524..bb630da34d7d97 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -7694,6 +7694,16 @@ TEST_F(FormatTest, BreakingBeforeNonAssignmentOperators) {
                Style);
 }
 
+TEST_F(FormatTest, EnumAssignmentContinuationIndentation) {
+  FormatStyle Style = getLLVMStyleWithColumns(30);
+  Style.BreakBeforeBinaryOperators = FormatStyle::BOS_NonAssignment;
+  verifyFormat("enum Flag {\n"
+               "  VeryLongFlagNameThatForcesBreak =\n"
+               "          1 << 2 << 3,\n"
+               "};",
+               Style);
+}
+
 TEST_F(FormatTest, AllowBinPackingInsideArguments) {
   FormatStyle Style = getLLVMStyleWithColumns(40);
   Style.BreakBeforeBinaryOperators = FormatStyle::BOS_NonAssignment;


        


More information about the cfe-commits mailing list