Author: Björn Schäpers Date: 2021-07-29T06:59:53-07:00 New Revision: 0e3777bb0ad94ecd1429dc96409177cdccf39bdd
URL: https://github.com/llvm/llvm-project/commit/0e3777bb0ad94ecd1429dc96409177cdccf39bdd DIFF: https://github.com/llvm/llvm-project/commit/0e3777bb0ad94ecd1429dc96409177cdccf39bdd.diff LOG: [clang-format] Fix aligning with linebreaks #2 This amends c5243c63cda3c740d6e9c7e501f6518c21688da3 to fix formatting continued function calls with BinPacking = false. Differential Revision: https://reviews.llvm.org/D106773 (cherry picked from commit 75f6a795ee0faf544c3f539d01008d1d5d876acb) Added: Modified: clang/lib/Format/WhitespaceManager.cpp clang/unittests/Format/FormatTest.cpp Removed: ################################################################################ diff --git a/clang/lib/Format/WhitespaceManager.cpp b/clang/lib/Format/WhitespaceManager.cpp index ca2222d1feffb..a822e0aaf1f93 100644 --- a/clang/lib/Format/WhitespaceManager.cpp +++ b/clang/lib/Format/WhitespaceManager.cpp @@ -347,7 +347,7 @@ AlignTokenSequence(const FormatStyle &Style, unsigned Start, unsigned End, if (ScopeStart > Start + 1 && Changes[ScopeStart - 2].Tok->is(tok::identifier) && Changes[ScopeStart - 1].Tok->is(tok::l_paren)) - return true; + return Style.BinPackArguments; // Ternary operator if (Changes[i].Tok->is(TT_ConditionalExpr)) diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index 3adf42d34cf13..de00864143f7b 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -16411,6 +16411,37 @@ TEST_F(FormatTest, AlignWithLineBreaks) { "}", Style); // clang-format on + + Style = getLLVMStyleWithColumns(120); + Style.AlignConsecutiveAssignments = FormatStyle::ACS_Consecutive; + Style.ContinuationIndentWidth = 4; + Style.IndentWidth = 4; + + // clang-format off + verifyFormat("void SomeFunc() {\n" + " newWatcher.maxAgeUsec = ToLegacyTimestamp(GetMaxAge(FromLegacyTimestamp<milliseconds>(monitorFrequencyUsec),\n" + " seconds(std::uint64_t(maxSampleAge)), maxKeepSamples));\n" + " newWatcher.maxAge = ToLegacyTimestamp(GetMaxAge(FromLegacyTimestamp<milliseconds>(monitorFrequencyUsec),\n" + " seconds(std::uint64_t(maxSampleAge)), maxKeepSamples));\n" + " newWatcher.max = ToLegacyTimestamp(GetMaxAge(FromLegacyTimestamp<milliseconds>(monitorFrequencyUsec),\n" + " seconds(std::uint64_t(maxSampleAge)), maxKeepSamples));\n" + "}", + Style); + // clang-format on + + Style.BinPackArguments = false; + + // clang-format off + verifyFormat("void SomeFunc() {\n" + " newWatcher.maxAgeUsec = ToLegacyTimestamp(GetMaxAge(\n" + " FromLegacyTimestamp<milliseconds>(monitorFrequencyUsec), seconds(std::uint64_t(maxSampleAge)), maxKeepSamples));\n" + " newWatcher.maxAge = ToLegacyTimestamp(GetMaxAge(\n" + " FromLegacyTimestamp<milliseconds>(monitorFrequencyUsec), seconds(std::uint64_t(maxSampleAge)), maxKeepSamples));\n" + " newWatcher.max = ToLegacyTimestamp(GetMaxAge(\n" + " FromLegacyTimestamp<milliseconds>(monitorFrequencyUsec), seconds(std::uint64_t(maxSampleAge)), maxKeepSamples));\n" + "}", + Style); + // clang-format on } TEST_F(FormatTest, AlignWithInitializerPeriods) { _______________________________________________ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits