r192297 - clang-format: Fix template declaration line breaking with comment.
Daniel Jasper
djasper at google.com
Wed Oct 9 08:06:17 PDT 2013
Author: djasper
Date: Wed Oct 9 10:06:17 2013
New Revision: 192297
URL: http://llvm.org/viewvc/llvm-project?rev=192297&view=rev
Log:
clang-format: Fix template declaration line breaking with comment.
Before, clang-format would always insert a linebreak before the comment
in code like:
template <typename T> // T can be A, B or C.
struct S {};
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=192297&r1=192296&r2=192297&view=diff
==============================================================================
--- cfe/trunk/lib/Format/ContinuationIndenter.cpp (original)
+++ cfe/trunk/lib/Format/ContinuationIndenter.cpp Wed Oct 9 10:06:17 2013
@@ -178,7 +178,8 @@ bool ContinuationIndenter::mustBreak(con
State.Stack.back().BreakBeforeParameter)
return true;
if ((Current.Type == TT_CtorInitializerColon ||
- (Previous.ClosesTemplateDeclaration && State.ParenLevel == 0)))
+ (Previous.ClosesTemplateDeclaration && State.ParenLevel == 0 &&
+ !Current.isTrailingComment())))
return true;
if ((Current.Type == TT_StartOfName || Current.is(tok::kw_operator)) &&
Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=192297&r1=192296&r2=192297&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Wed Oct 9 10:06:17 2013
@@ -3586,6 +3586,9 @@ TEST_F(FormatTest, WrapsTemplateDeclarat
" template <typename> class Baaaaaaar>\n"
"struct C {};",
AlwaysBreak);
+ verifyFormat("template <typename T> // T can be A, B or C.\n"
+ "struct C {};",
+ AlwaysBreak);
}
TEST_F(FormatTest, WrapsAtNestedNameSpecifiers) {
More information about the cfe-commits
mailing list