Author: djasper
Date: Fri Sep 27 02:49:08 2013
New Revision: 191492
URL: http://llvm.org/viewvc/llvm-project?rev=191492&view=rev
Log:
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() {}
Modified:
cfe/trunk/lib/Format/ContinuationIndenter.cpp
cfe/trunk/unittests/Format/FormatTest.cpp
Modified: cfe/trunk/lib/Format/ContinuationIndenter.cpp
URL:
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/ContinuationIndenter.cpp?rev=191492&r1=191491&r2=191492&view=diff
==============================================================================
--- cfe/trunk/lib/Format/ContinuationIndenter.cpp (original)
+++ cfe/trunk/lib/Format/ContinuationIndenter.cpp Fri Sep 27 02:49:08 2013
@@ -192,6 +192,8 @@ unsigned ContinuationIndenter::addTokenT
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 @@ unsigned ContinuationIndenter::addTokenT
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 &&
Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL:
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=191492&r1=191491&r2=191492&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Fri Sep 27 02:49:08 2013
@@ -3500,6 +3500,9 @@ TEST_F(FormatTest, WrapsAtFunctionCallsI
TEST_F(FormatTest, WrapsTemplateDeclarations) {
verifyFormat("template <typename T>\n"
"virtual void loooooooooooongFunction(int Param1, int
Param2);");
+ verifyFormat("template <typename T>\n"
+ "// T should be one of {A, B}.\n"
+ "virtual void loooooooooooongFunction(int Param1, int
Param2);");
verifyFormat(
"template <typename T>\n"
"using comment_to_xml_conversion = comment_to_xml_conversion<T, int>;");
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits