[clang] e21db15 - [clang-format] Honour PointerAlignment in statements with initializers.
Marek Kurdej via cfe-commits
cfe-commits at lists.llvm.org
Tue Feb 15 09:06:38 PST 2022
Author: Marek Kurdej
Date: 2022-02-15T18:06:32+01:00
New Revision: e21db15be8126004304b813e5ff87c7ecbed06bf
URL: https://github.com/llvm/llvm-project/commit/e21db15be8126004304b813e5ff87c7ecbed06bf
DIFF: https://github.com/llvm/llvm-project/commit/e21db15be8126004304b813e5ff87c7ecbed06bf.diff
LOG: [clang-format] Honour PointerAlignment in statements with initializers.
Fixes https://github.com/llvm/llvm-project/issues/53843.
Reviewed By: HazardyKnusperkeks, owenpan
Differential Revision: https://reviews.llvm.org/D119814
Added:
Modified:
clang/lib/Format/TokenAnnotator.cpp
clang/unittests/Format/FormatTest.cpp
Removed:
################################################################################
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp
index 72f49478d5b4b..a2985eb75a195 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -3142,7 +3142,8 @@ bool TokenAnnotator::spaceRequiredBetween(const AnnotatedLine &Line,
// initializers.
if (Line.IsMultiVariableDeclStmt &&
(Left.NestingLevel == Line.First->NestingLevel ||
- startsWithInitStatement(Line)))
+ ((Left.NestingLevel == Line.First->NestingLevel + 1) &&
+ startsWithInitStatement(Line))))
return false;
return Left.Previous && !Left.Previous->isOneOf(
tok::l_paren, tok::coloncolon, tok::l_square);
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index d230964cd2860..1b99b53bbee55 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -8417,6 +8417,13 @@ TEST_F(FormatTest, DeclarationsOfMultipleVariables) {
verifyFormat(
"/*comment*/ switch (int *p, *q; p != q) {\n default:\n break;\n}",
Style);
+
+ verifyFormat("if ([](int* p, int* q) {}()) {\n}", Style);
+ verifyFormat("for ([](int* p, int* q) {}();;) {\n}", Style);
+ verifyFormat("for (; [](int* p, int* q) {}();) {\n}", Style);
+ verifyFormat("for (;; [](int* p, int* q) {}()) {\n}", Style);
+ verifyFormat("switch ([](int* p, int* q) {}()) {\n default:\n break;\n}",
+ Style);
}
TEST_F(FormatTest, ConditionalExpressionsInBrackets) {
More information about the cfe-commits
mailing list