[clang] [clang-format] Fix a bug in `AlignAfterOpenBracket: DontAlign` (PR #94561)
via cfe-commits
cfe-commits at lists.llvm.org
Wed Jun 5 20:01:35 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang-format
Author: Owen Pan (owenca)
<details>
<summary>Changes</summary>
Fixes #<!-- -->94555.
---
Full diff: https://github.com/llvm/llvm-project/pull/94561.diff
2 Files Affected:
- (modified) clang/lib/Format/ContinuationIndenter.cpp (+1-1)
- (modified) clang/unittests/Format/FormatTest.cpp (+8)
``````````diff
diff --git a/clang/lib/Format/ContinuationIndenter.cpp b/clang/lib/Format/ContinuationIndenter.cpp
index 6b9fbfe0ebf53..be684ac71cd61 100644
--- a/clang/lib/Format/ContinuationIndenter.cpp
+++ b/clang/lib/Format/ContinuationIndenter.cpp
@@ -1712,7 +1712,7 @@ void ContinuationIndenter::moveStatePastFakeLParens(LineState &State,
(!Previous || Previous->isNot(tok::kw_return) ||
(Style.Language != FormatStyle::LK_Java && PrecedenceLevel > 0)) &&
(Style.AlignAfterOpenBracket != FormatStyle::BAS_DontAlign ||
- PrecedenceLevel != prec::Comma || Current.NestingLevel == 0) &&
+ PrecedenceLevel > prec::Comma || Current.NestingLevel == 0) &&
(!Style.isTableGen() ||
(Previous && Previous->isOneOf(TT_TableGenDAGArgListComma,
TT_TableGenDAGArgListCommaToBreak)))) {
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index 4e427268fb82a..dbc1916825f33 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -9241,6 +9241,14 @@ TEST_F(FormatTest, AlignsAfterOpenBracket) {
" b));",
Style);
+ Style.ColumnLimit = 30;
+ verifyFormat("for (int foo = 0; foo < FOO;\n"
+ " ++foo) {\n"
+ " bar(foo);\n"
+ "}",
+ Style);
+ Style.ColumnLimit = 80;
+
Style.AlignAfterOpenBracket = FormatStyle::BAS_AlwaysBreak;
Style.BinPackArguments = false;
Style.BinPackParameters = false;
``````````
</details>
https://github.com/llvm/llvm-project/pull/94561
More information about the cfe-commits
mailing list