diff options
| author | Krasimir Georgiev <krasimir@google.com> | 2017-01-31 15:40:15 +0000 |
|---|---|---|
| committer | Krasimir Georgiev <krasimir@google.com> | 2017-01-31 15:40:15 +0000 |
| commit | b796cebf3f749cc850173a61eedac56fd063acb0 (patch) | |
| tree | 07ed4ae30e8bf298cf55689ccf923764e0ca5f42 /clang/lib/Format | |
| parent | 7d9eaf713cbce26bcec432da3c7a1768b366a4d5 (diff) | |
| download | bcm5719-llvm-b796cebf3f749cc850173a61eedac56fd063acb0.tar.gz bcm5719-llvm-b796cebf3f749cc850173a61eedac56fd063acb0.zip | |
[clang-format] Fix regression about adding leading whitespace to the content of line comments
Summary:
The reflower didn't measure precisely the line column of a line in the middle of
a line comment section that has a prefix that needs to be adapted.
source:
```
/// a
//b
```
format before:
```
/// a
//b
```
format after:
```
/// a
// b
```
Reviewers: djasper
Reviewed By: djasper
Subscribers: sammccall, cfe-commits, klimek
Differential Revision: https://reviews.llvm.org/D29329
llvm-svn: 293641
Diffstat (limited to 'clang/lib/Format')
| -rw-r--r-- | clang/lib/Format/BreakableToken.cpp | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/clang/lib/Format/BreakableToken.cpp b/clang/lib/Format/BreakableToken.cpp index 683d6e7249b..148656080d3 100644 --- a/clang/lib/Format/BreakableToken.cpp +++ b/clang/lib/Format/BreakableToken.cpp @@ -796,10 +796,13 @@ void BreakableLineCommentSection::replaceWhitespaceBefore( } else { // This is the first line for the current token, but no reflow with the // previous token is necessary. However, we still may need to adjust the - // start column. + // start column. Note that ContentColumn[LineIndex] is the expected + // content column after a possible update to the prefix, hence the prefix + // length change is included. unsigned LineColumn = ContentColumn[LineIndex] - - (Content[LineIndex].data() - Lines[LineIndex].data()); + (Content[LineIndex].data() - Lines[LineIndex].data()) + + (OriginalPrefix[LineIndex].size() - Prefix[LineIndex].size()); if (tokenAt(LineIndex).OriginalColumn != LineColumn) { Whitespaces.replaceWhitespace(*Tokens[LineIndex], /*Newlines=*/1, @@ -813,13 +816,14 @@ void BreakableLineCommentSection::replaceWhitespaceBefore( /*InPPDirective=*/false); } } - } else if (OriginalPrefix[LineIndex] != Prefix[LineIndex]) { - // This is not the first line of the token. Adjust the prefix if necessary. + } + if (OriginalPrefix[LineIndex] != Prefix[LineIndex]) { + // Adjust the prefix if necessary. // Take care of the space possibly introduced after a decoration. assert(Prefix[LineIndex] == (OriginalPrefix[LineIndex] + " ").str() && - "Expecting a block comment decoration to differ from original by " - "at most a space"); + "Expecting a line comment prefix to differ from original by at most " + "a space"); Whitespaces.replaceWhitespaceInToken( tokenAt(LineIndex), OriginalPrefix[LineIndex].size(), 0, "", "", /*InPPDirective=*/false, /*Newlines=*/0, /*Spaces=*/1); |

