summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Jasper <djasper@google.com>2014-10-07 14:45:34 +0000
committerDaniel Jasper <djasper@google.com>2014-10-07 14:45:34 +0000
commit4281c5ae01f2824fbff9af1d568d4e0e29a0ed82 (patch)
treeebcac9b03f715698501199a9226851b9c63ba678
parent219b20e1a3d5438c4ba8a0ef22900d3587d0fc19 (diff)
downloadbcm5719-llvm-4281c5ae01f2824fbff9af1d568d4e0e29a0ed82.tar.gz
bcm5719-llvm-4281c5ae01f2824fbff9af1d568d4e0e29a0ed82.zip
clang-format: Fix bug with comments between non-trival parameters.
Before: SomeFunction(a, a, // comment b + x); After: SomeFunction(a, a, // comment b + x); llvm-svn: 219209
-rw-r--r--clang/lib/Format/ContinuationIndenter.cpp7
-rw-r--r--clang/unittests/Format/FormatTest.cpp6
2 files changed, 10 insertions, 3 deletions
diff --git a/clang/lib/Format/ContinuationIndenter.cpp b/clang/lib/Format/ContinuationIndenter.cpp
index c48df870416..9d72994c1bf 100644
--- a/clang/lib/Format/ContinuationIndenter.cpp
+++ b/clang/lib/Format/ContinuationIndenter.cpp
@@ -487,7 +487,7 @@ unsigned ContinuationIndenter::getNewLineColumn(const LineState &State) {
if (!State.NextToken || !State.NextToken->Previous)
return 0;
FormatToken &Current = *State.NextToken;
- const FormatToken &Previous = *State.NextToken->Previous;
+ const FormatToken &Previous = *Current.Previous;
// If we are continuing an expression, we want to use the continuation indent.
unsigned ContinuationIndent =
std::max(State.Stack.back().LastSpace, State.Stack.back().Indent) +
@@ -717,7 +717,8 @@ void ContinuationIndenter::moveStatePastFakeLParens(LineState &State,
// Indent from 'LastSpace' unless this the fake parentheses encapsulating a
// builder type call after 'return'. If such a call is line-wrapped, we
// commonly just want to indent from the start of the line.
- if (!Previous || Previous->isNot(tok::kw_return) || *I > 0)
+ if (!Current.isTrailingComment() &&
+ (!Previous || Previous->isNot(tok::kw_return) || *I > 0))
NewParenState.Indent =
std::max(std::max(State.Column, NewParenState.Indent),
State.Stack.back().LastSpace);
@@ -756,7 +757,7 @@ void ContinuationIndenter::moveStatePastFakeLParens(LineState &State,
// other expression, unless the indentation needs to be skipped.
if (*I == prec::Conditional ||
(!SkipFirstExtraIndent && *I > prec::Assignment &&
- !Style.BreakBeforeBinaryOperators))
+ !Current.isTrailingComment() && !Style.BreakBeforeBinaryOperators))
NewParenState.Indent += Style.ContinuationIndentWidth;
if ((Previous && !Previous->opensScope()) || *I > prec::Comma)
NewParenState.BreakBeforeParameter = false;
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index 0842711749d..29f494603c6 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -832,6 +832,12 @@ TEST_F(FormatTest, UnderstandsSingleLineComments) {
verifyFormat("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa =\n"
" // Comment inside a statement.\n"
" bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb;");
+ verifyFormat("SomeFunction(a,\n"
+ " // comment\n"
+ " b + x);");
+ verifyFormat("SomeFunction(a, a,\n"
+ " // comment\n"
+ " b + x);");
verifyFormat(
"bool aaaaaaaaaaaaa = // comment\n"
" aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa || aaaaaaaaaaaaaaaaaaaaaaaaaaaa ||\n"
OpenPOWER on IntegriCloud