[clang] 5109737 - [clang-format] Fix indentation for array variables with alignment of consecutive assignments and declarations.
Marek Kurdej via cfe-commits
cfe-commits at lists.llvm.org
Wed Jan 5 04:52:51 PST 2022
Author: Marek Kurdej
Date: 2022-01-05T13:52:45+01:00
New Revision: 5109737c924d68323b1982949a3e28ef26bc289e
URL: https://github.com/llvm/llvm-project/commit/5109737c924d68323b1982949a3e28ef26bc289e
DIFF: https://github.com/llvm/llvm-project/commit/5109737c924d68323b1982949a3e28ef26bc289e.diff
LOG: [clang-format] Fix indentation for array variables with alignment of consecutive assignments and declarations.
Fixes https://github.com/llvm/llvm-project/issues/52914.
Reviewed By: HazardyKnusperkeks, owenpan
Differential Revision: https://reviews.llvm.org/D116527
Added:
Modified:
clang/lib/Format/WhitespaceManager.cpp
clang/unittests/Format/FormatTest.cpp
Removed:
################################################################################
diff --git a/clang/lib/Format/WhitespaceManager.cpp b/clang/lib/Format/WhitespaceManager.cpp
index f0e0247ce33e..3f87e70fb90c 100644
--- a/clang/lib/Format/WhitespaceManager.cpp
+++ b/clang/lib/Format/WhitespaceManager.cpp
@@ -368,6 +368,13 @@ AlignTokenSequence(const FormatStyle &Style, unsigned Start, unsigned End,
Changes[i].Tok->Previous->is(TT_ConditionalExpr))
return true;
+ // Continued braced list.
+ if (ScopeStart > Start + 1 &&
+ Changes[ScopeStart - 2].Tok->isNot(tok::identifier) &&
+ Changes[ScopeStart - 1].Tok->is(tok::l_brace) &&
+ Changes[i].Tok->isNot(tok::r_brace))
+ return true;
+
return false;
};
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index 1d622e80ed12..d90c3d3a291f 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -16427,6 +16427,11 @@ TEST_F(FormatTest, AlignConsecutiveDeclarations) {
" double bar();\n"
"};\n",
Alignment);
+ // http://llvm.org/PR52914
+ verifyFormat("char *a[] = {\"a\", // comment\n"
+ " \"bb\"};\n"
+ "int bbbbbbb = 0;",
+ Alignment);
// PAS_Right
EXPECT_EQ("void SomeFunction(int parameter = 0) {\n"
More information about the cfe-commits
mailing list