Author: Owen Pan Date: 2024-01-22T18:59:08-08:00 New Revision: 3b171cb968b3f8495b096139fc57ff6263727e40
URL: https://github.com/llvm/llvm-project/commit/3b171cb968b3f8495b096139fc57ff6263727e40 DIFF: https://github.com/llvm/llvm-project/commit/3b171cb968b3f8495b096139fc57ff6263727e40.diff LOG: [clang-format] Fix a bug in ContinuationIndenter (#78921) Fixes #76991. Added: Modified: clang/lib/Format/ContinuationIndenter.cpp clang/lib/Format/WhitespaceManager.h clang/unittests/Format/FormatTest.cpp Removed: ################################################################################ diff --git a/clang/lib/Format/ContinuationIndenter.cpp b/clang/lib/Format/ContinuationIndenter.cpp index ddbee15cb159f6..a099813c9100b4 100644 --- a/clang/lib/Format/ContinuationIndenter.cpp +++ b/clang/lib/Format/ContinuationIndenter.cpp @@ -740,7 +740,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 a0825dc2ad4ef1..fa3bea5ae5d755 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -21215,6 +21215,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" _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits