r311532 - [clang-format] Align trailing comments if ColumnLimit is 0
Hans Wennborg via cfe-commits
cfe-commits at lists.llvm.org
Wed Aug 23 09:50:28 PDT 2017
Merged to 5.0 in r311573.
On Wed, Aug 23, 2017 at 12:18 AM, Krasimir Georgiev via cfe-commits
<cfe-commits at lists.llvm.org> wrote:
> Author: krasimir
> Date: Wed Aug 23 00:18:36 2017
> New Revision: 311532
>
> URL: http://llvm.org/viewvc/llvm-project?rev=311532&view=rev
> Log:
> [clang-format] Align trailing comments if ColumnLimit is 0
>
> Summary:
> ColumnLimit = 0 means no limit, so comment should always be aligned if requested. This was broken with
>
> https://llvm.org/svn/llvm-project/cfe/trunk@304687
>
> introduced via
>
> https://reviews.llvm.org/D33830
>
> and is included in 5.0.0-rc2. This commit fixes it and adds a unittest for this property.
>
> Should go into clang-5.0 IMHO.
>
> Contributed by @pboettch!
>
> Reviewers: djasper, krasimir
>
> Reviewed By: djasper, krasimir
>
> Subscribers: hans, klimek
>
> Differential Revision: https://reviews.llvm.org/D36967
>
> Modified:
> cfe/trunk/lib/Format/WhitespaceManager.cpp
> cfe/trunk/unittests/Format/FormatTestComments.cpp
>
> Modified: cfe/trunk/lib/Format/WhitespaceManager.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/WhitespaceManager.cpp?rev=311532&r1=311531&r2=311532&view=diff
> ==============================================================================
> --- cfe/trunk/lib/Format/WhitespaceManager.cpp (original)
> +++ cfe/trunk/lib/Format/WhitespaceManager.cpp Wed Aug 23 00:18:36 2017
> @@ -472,9 +472,14 @@ void WhitespaceManager::alignTrailingCom
> continue;
>
> unsigned ChangeMinColumn = Changes[i].StartOfTokenColumn;
> - unsigned ChangeMaxColumn = Style.ColumnLimit >= Changes[i].TokenLength
> - ? Style.ColumnLimit - Changes[i].TokenLength
> - : ChangeMinColumn;
> + unsigned ChangeMaxColumn;
> +
> + if (Style.ColumnLimit == 0)
> + ChangeMaxColumn = UINT_MAX;
> + else if (Style.ColumnLimit >= Changes[i].TokenLength)
> + ChangeMaxColumn = Style.ColumnLimit - Changes[i].TokenLength;
> + else
> + ChangeMaxColumn = ChangeMinColumn;
>
> // If we don't create a replacement for this change, we have to consider
> // it to be immovable.
>
> Modified: cfe/trunk/unittests/Format/FormatTestComments.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTestComments.cpp?rev=311532&r1=311531&r2=311532&view=diff
> ==============================================================================
> --- cfe/trunk/unittests/Format/FormatTestComments.cpp (original)
> +++ cfe/trunk/unittests/Format/FormatTestComments.cpp Wed Aug 23 00:18:36 2017
> @@ -2476,6 +2476,13 @@ TEST_F(FormatTestComments, AlignTrailing
> "int k; // line longg long",
> getLLVMStyleWithColumns(20)));
>
> + // Always align if ColumnLimit = 0
> + EXPECT_EQ("int i, j; // line 1\n"
> + "int k; // line longg long",
> + format("int i, j; // line 1\n"
> + "int k; // line longg long",
> + getLLVMStyleWithColumns(0)));
> +
> // Align comment line sections aligned with the next token with the next
> // token.
> EXPECT_EQ("class A {\n"
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
More information about the cfe-commits
mailing list