[clang] [clang-format] Fix a bug in ContinuationIndenter (PR #78921)
via cfe-commits
cfe-commits at lists.llvm.org
Sun Jan 21 17:19:14 PST 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang-format
Author: Owen Pan (owenca)
<details>
<summary>Changes</summary>
Fixes #<!-- -->76991.
---
Full diff: https://github.com/llvm/llvm-project/pull/78921.diff
3 Files Affected:
- (modified) clang/lib/Format/ContinuationIndenter.cpp (+2-1)
- (modified) clang/lib/Format/WhitespaceManager.h (+1-1)
- (modified) clang/unittests/Format/FormatTest.cpp (+7)
``````````diff
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"
``````````
</details>
https://github.com/llvm/llvm-project/pull/78921
More information about the cfe-commits
mailing list