clang-format: Fix formatting bug with comment in weird place.
Before:
template <typename T>
// T should be one of {A, B}.
void f() {}
After:
template <typename T>
// T should be one of {A, B}.
void f() {}
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@191492 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Format/ContinuationIndenter.cpp b/lib/Format/ContinuationIndenter.cpp
index 87c0222..8b0baea 100644
--- a/lib/Format/ContinuationIndenter.cpp
+++ b/lib/Format/ContinuationIndenter.cpp
@@ -192,6 +192,8 @@
unsigned ExtraSpaces) {
const FormatToken &Current = *State.NextToken;
const FormatToken &Previous = *State.NextToken->Previous;
+ const FormatToken *PreviousNonComment =
+ State.NextToken->getPreviousNonComment();
// Extra penalty that needs to be added because of the way certain line
// breaks are chosen.
@@ -253,7 +255,8 @@
State.Column = State.Stack.back().QuestionColumn;
} else if (Previous.is(tok::comma) && State.Stack.back().VariablePos != 0) {
State.Column = State.Stack.back().VariablePos;
- } else if (Previous.ClosesTemplateDeclaration ||
+ } else if ((PreviousNonComment &&
+ PreviousNonComment->ClosesTemplateDeclaration) ||
((Current.Type == TT_StartOfName ||
Current.is(tok::kw_operator)) &&
State.ParenLevel == 0 &&