llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-clang-format Author: Priyanshu Ranjan (priyanshujaiz) <details> <summary>Changes</summary> Fixes #<!-- -->229206. When `BreakBeforeBinaryOperators: All` is configured, formatting a variable definition with an attribute (e.g. `[[maybe_unused]]`) between the variable name and the assignment previously caused the assignment operator to lose all continuation indentation (starting at column 0). The root cause was in `ContinuationIndenter::getNewLineColumn()`. The logic assumed that any token following an attribute closing bracket (`TT_AttributeRSquare`) should not be indented as a continuation. It failed to account for binary operators (like `=`) which are valid continuations of the variable declaration statement. This patch updates the condition to `!Current.isBinaryOperator()`, ensuring that assignment operators following attributes correctly fall through to the standard continuation indentation logic. A regression test has been added to `FormatTest.BreakBinaryOperatorsInPresenceOfTemplates` to verify the 4-space continuation indent is correctly applied when formatting wraps at the column limit. Assisted-by: Antigravity AI --- Full diff: https://github.com/llvm/llvm-project/pull/230417.diff 2 Files Affected: - (modified) clang/lib/Format/ContinuationIndenter.cpp (+3-2) - (modified) clang/unittests/Format/FormatTest.cpp (+9) ``````````diff diff --git a/clang/lib/Format/ContinuationIndenter.cpp b/clang/lib/Format/ContinuationIndenter.cpp index bb8179cbc4f95..636ab7d24ee31 100644 --- a/clang/lib/Format/ContinuationIndenter.cpp +++ b/clang/lib/Format/ContinuationIndenter.cpp @@ -1692,10 +1692,11 @@ ContinuationIndenter::getNewLineColumn(const LineState &State) { Current.isNot(tok::l_paren) && !Current.endsSequence(TT_StartOfName, TT_AttributeMacro, TT_PointerOrReference)) || - PreviousNonComment->isOneOf(TT_AttributeRParen, TT_AttributeRSquare, + (PreviousNonComment->isOneOf(TT_AttributeRParen, TT_AttributeRSquare, TT_FunctionAnnotationRParen, TT_JavaAnnotation, - TT_LeadingJavaAnnotation))) || + TT_LeadingJavaAnnotation) && + !Current.isBinaryOperator()))) || (!Style.IndentWrappedFunctionNames && NextNonComment->isOneOf(tok::kw_operator, TT_FunctionDeclarationName)) || (State.Line->ReturnTypeWrapped && PreviousNonComment && diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index d346036448140..c77a0db87d31b 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -7790,6 +7790,15 @@ TEST_F(FormatTest, BreakBinaryOperatorsInPresenceOfTemplates) { " and is_swappable_v<hash<T>>\n" " and is_callable_v<hash<T>(T)>;", Style); + + FormatStyle Style80 = getLLVMStyle(); + Style80.BreakBeforeBinaryOperators = FormatStyle::BOS_All; + verifyFormat("static constexpr long long variable_with_long_name_without_attribute\n" + " = 1234567890;\n" + "static constexpr long long long_variable_with_attribute " + "[[maybe_unused]]\n" + " = 9876543210;", + Style80); } TEST_F(FormatTest, ConstructorInitializers) { `````````` </details> https://github.com/llvm/llvm-project/pull/230417 _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
