Skip to content

Commit e21db15

Browse files
committed
[clang-format] Honour PointerAlignment in statements with initializers.
Fixes llvm/llvm-project#53843. Reviewed By: HazardyKnusperkeks, owenpan Differential Revision: https://reviews.llvm.org/D119814
1 parent 9371d95 commit e21db15

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

clang/lib/Format/TokenAnnotator.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3142,7 +3142,8 @@ bool TokenAnnotator::spaceRequiredBetween(const AnnotatedLine &Line,
31423142
// initializers.
31433143
if (Line.IsMultiVariableDeclStmt &&
31443144
(Left.NestingLevel == Line.First->NestingLevel ||
3145-
startsWithInitStatement(Line)))
3145+
((Left.NestingLevel == Line.First->NestingLevel + 1) &&
3146+
startsWithInitStatement(Line))))
31463147
return false;
31473148
return Left.Previous && !Left.Previous->isOneOf(
31483149
tok::l_paren, tok::coloncolon, tok::l_square);

clang/unittests/Format/FormatTest.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8417,6 +8417,13 @@ TEST_F(FormatTest, DeclarationsOfMultipleVariables) {
84178417
verifyFormat(
84188418
"/*comment*/ switch (int *p, *q; p != q) {\n default:\n break;\n}",
84198419
Style);
8420+
8421+
verifyFormat("if ([](int* p, int* q) {}()) {\n}", Style);
8422+
verifyFormat("for ([](int* p, int* q) {}();;) {\n}", Style);
8423+
verifyFormat("for (; [](int* p, int* q) {}();) {\n}", Style);
8424+
verifyFormat("for (;; [](int* p, int* q) {}()) {\n}", Style);
8425+
verifyFormat("switch ([](int* p, int* q) {}()) {\n default:\n break;\n}",
8426+
Style);
84208427
}
84218428

84228429
TEST_F(FormatTest, ConditionalExpressionsInBrackets) {

0 commit comments

Comments
 (0)