[clang] [clang-format] Fix a bug in ContinuationIndenter (PR #78921)
Owen Pan via cfe-commits
cfe-commits at lists.llvm.org
Sun Jan 21 17:18:42 PST 2024
https://github.com/owenca created https://github.com/llvm/llvm-project/pull/78921
Fixes #76991.
>From bc3f566b7c512434179241796a2d7d4ac3e7b381 Mon Sep 17 00:00:00 2001
From: Owen Pan <owenpiano at gmail.com>
Date: Sun, 21 Jan 2024 17:14:53 -0800
Subject: [PATCH] [clang-format] Fix a bug in ContinuationIndenter
Fixes #76991.
---
clang/lib/Format/ContinuationIndenter.cpp | 3 ++-
clang/lib/Format/WhitespaceManager.h | 2 +-
clang/unittests/Format/FormatTest.cpp | 7 +++++++
3 files changed, 10 insertions(+), 2 deletions(-)
diff --git a/clang/lib/Format/ContinuationIndenter.cpp b/clang/lib/Format/ContinuationIndenter.cpp
index e6eaaa9ab45706..c204cc81331521 100644
--- a/clang/lib/Format/ContinuationIndenter.cpp
+++ b/clang/lib/Format/ContinuationIndenter.cpp
@@ -738,7 +738,8 @@ void ContinuationIndenter::addTokenOnCurrentLine(LineState &State, bool DryRun,
if (!DryRun) {
Whitespaces.replaceWhitespace(Current, /*Newlines=*/0, Spaces,
- State.Column + Spaces + PPColumnCorrection);
+ State.Column + Spaces + PPColumnCorrection,
+ /*IsAligned=*/false, State.Line->InMacroBody);
}
// If "BreakBeforeInheritanceComma" mode, don't break within the inheritance
diff --git a/clang/lib/Format/WhitespaceManager.h b/clang/lib/Format/WhitespaceManager.h
index dc6f60e5deeedf..8ac73305871ae7 100644
--- a/clang/lib/Format/WhitespaceManager.h
+++ b/clang/lib/Format/WhitespaceManager.h
@@ -55,7 +55,7 @@ class WhitespaceManager {
/// this replacement. It is needed for determining how \p Spaces is turned
/// into tabs and spaces for some format styles.
void replaceWhitespace(FormatToken &Tok, unsigned Newlines, unsigned Spaces,
- unsigned StartOfTokenColumn, bool isAligned = false,
+ unsigned StartOfTokenColumn, bool IsAligned = false,
bool InPPDirective = false);
/// Adds information about an unchangeable token's whitespace.
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index 3fb55ae2c1f413..a42a254d61d419 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -21203,6 +21203,13 @@ TEST_F(FormatTest, CatchAlignArrayOfStructuresLeftAlignment) {
"});",
Style);
+ Style.AlignEscapedNewlines = FormatStyle::ENAS_DontAlign;
+ verifyFormat("#define FOO \\\n"
+ " int foo[][2] = { \\\n"
+ " {0, 1} \\\n"
+ " };",
+ Style);
+
Style.Cpp11BracedListStyle = false;
verifyFormat("struct test demo[] = {\n"
" { 56, 23, \"hello\" },\n"
More information about the cfe-commits
mailing list