diff options
author | Krasimir Georgiev <krasimir@google.com> | 2017-08-22 14:40:05 +0000 |
---|---|---|
committer | Krasimir Georgiev <krasimir@google.com> | 2017-08-22 14:40:05 +0000 |
commit | fe268fc1c892d28f95aec842390e0a69c2074b5a (patch) | |
tree | e112d70258050939251c397e26237dfdc8c220bd /clang/unittests/Format/FormatTestComments.cpp | |
parent | 5fb51ddf293b7eb0da5589d0bc4844eba7c17229 (diff) | |
download | bcm5719-llvm-fe268fc1c892d28f95aec842390e0a69c2074b5a.tar.gz bcm5719-llvm-fe268fc1c892d28f95aec842390e0a69c2074b5a.zip |
[clang-format] Break non-trailing block comments
Summary:
This patch is an alternative to https://reviews.llvm.org/D36614, by resolving a
non-idempotency issue by breaking non-trailing comments:
Consider formatting the following code with column limit at `V`:
```
V
const /* comment comment */ A = B;
```
The comment is not a trailing comment, breaking before it doesn't bring it under
the column limit. The formatter breaks after it, resulting in:
```
V
const /* comment comment */
A = B;
```
For a next reformat, the formatter considers the comment as a trailing comment,
so it is free to break it further, resulting in:
```
V
const /* comment
comment */
A = B;
```
This patch improves the situation by directly producing the third case.
Reviewers: djasper
Reviewed By: djasper
Subscribers: cfe-commits, klimek
Differential Revision: https://reviews.llvm.org/D37007
llvm-svn: 311457
Diffstat (limited to 'clang/unittests/Format/FormatTestComments.cpp')
-rw-r--r-- | clang/unittests/Format/FormatTestComments.cpp | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/clang/unittests/Format/FormatTestComments.cpp b/clang/unittests/Format/FormatTestComments.cpp index d1cf10bffca..ffcfb3cfe8b 100644 --- a/clang/unittests/Format/FormatTestComments.cpp +++ b/clang/unittests/Format/FormatTestComments.cpp @@ -2780,6 +2780,22 @@ TEST_F(FormatTestComments, AlignsBlockCommentDecorations) { "* long */", getLLVMStyleWithColumns(20))); } + +TEST_F(FormatTestComments, NonTrailingBlockComments) { + verifyFormat("const /** comment comment */ A = B;", + getLLVMStyleWithColumns(40)); + + verifyFormat("const /** comment comment comment */ A =\n" + " B;", + getLLVMStyleWithColumns(40)); + + EXPECT_EQ("const /** comment comment comment\n" + " comment */\n" + " A = B;", + format("const /** comment comment comment comment */\n" + " A = B;", + getLLVMStyleWithColumns(40))); +} } // end namespace } // end namespace format } // end namespace clang |