summaryrefslogtreecommitdiffstats
path: root/clang/lib
diff options
context:
space:
mode:
authorDaniel Jasper <djasper@google.com>2014-05-07 09:23:05 +0000
committerDaniel Jasper <djasper@google.com>2014-05-07 09:23:05 +0000
commit8acf822b6fdebddc08d9f1b3614e83491a43b32c (patch)
tree908ea523c7f7b25bbc5ecf010a3fdf33f9cb0b4c /clang/lib
parent5d174547a9788ecb15ba33abbb4ef2e1abee0ba3 (diff)
downloadbcm5719-llvm-8acf822b6fdebddc08d9f1b3614e83491a43b32c.tar.gz
bcm5719-llvm-8acf822b6fdebddc08d9f1b3614e83491a43b32c.zip
clang-format: Fix corner cases for comments in if conditions.
Before: if ( // a x + 3) { .. After: if ( // a x + 3) { .. llvm-svn: 208175
Diffstat (limited to 'clang/lib')
-rw-r--r--clang/lib/Format/ContinuationIndenter.cpp5
-rw-r--r--clang/lib/Format/TokenAnnotator.cpp2
2 files changed, 4 insertions, 3 deletions
diff --git a/clang/lib/Format/ContinuationIndenter.cpp b/clang/lib/Format/ContinuationIndenter.cpp
index f18984bb15b..d225bce8bfb 100644
--- a/clang/lib/Format/ContinuationIndenter.cpp
+++ b/clang/lib/Format/ContinuationIndenter.cpp
@@ -290,10 +290,11 @@ void ContinuationIndenter::addTokenOnCurrentLine(LineState &State, bool DryRun,
State.Stack.back().ContainsUnwrappedBuilder = true;
State.Column += Spaces;
- if (Current.is(tok::l_paren) && Previous.isOneOf(tok::kw_if, tok::kw_for))
+ if (Current.isNot(tok::comment) && Previous.is(tok::l_paren) &&
+ Previous.Previous && Previous.Previous->isOneOf(tok::kw_if, tok::kw_for))
// Treat the condition inside an if as if it was a second function
// parameter, i.e. let nested calls have a continuation indent.
- State.Stack.back().LastSpace = State.Column + 1; // 1 is length of "(".
+ State.Stack.back().LastSpace = State.Column;
else if (Current.isNot(tok::comment) &&
(Previous.is(tok::comma) ||
(Previous.is(tok::colon) && Previous.Type == TT_ObjCMethodExpr)))
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp
index a41992679ad..21cec905a8e 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -1667,7 +1667,7 @@ bool TokenAnnotator::canBreakBefore(const AnnotatedLine &Line,
return false;
if (Left.is(tok::l_paren) && Left.Previous &&
(Left.Previous->Type == TT_BinaryOperator ||
- Left.Previous->Type == TT_CastRParen))
+ Left.Previous->Type == TT_CastRParen || Left.Previous->is(tok::kw_if)))
return false;
if (Right.Type == TT_ImplicitStringLiteral)
return false;
OpenPOWER on IntegriCloud