From 6e7f1934f489b48a53b8c9af314921c0e55ee5b5 Mon Sep 17 00:00:00 2001 From: Daniel Jasper Date: Wed, 9 Oct 2013 15:06:17 +0000 Subject: [PATCH] clang-format: Fix template declaration line breaking with comment. Before, clang-format would always insert a linebreak before the comment in code like: template // T can be A, B or C. struct S {}; git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@192297 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Format/ContinuationIndenter.cpp | 3 ++- unittests/Format/FormatTest.cpp | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/Format/ContinuationIndenter.cpp b/lib/Format/ContinuationIndenter.cpp index 3714088306..560e65ea68 100644 --- a/lib/Format/ContinuationIndenter.cpp +++ b/lib/Format/ContinuationIndenter.cpp @@ -178,7 +178,8 @@ bool ContinuationIndenter::mustBreak(const LineState &State) { 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)) && diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index 4a51448f33..10d7413d42 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -3586,6 +3586,9 @@ TEST_F(FormatTest, WrapsTemplateDeclarations) { " template class Baaaaaaar>\n" "struct C {};", AlwaysBreak); + verifyFormat("template // T can be A, B or C.\n" + "struct C {};", + AlwaysBreak); } TEST_F(FormatTest, WrapsAtNestedNameSpecifiers) { -- 2.40.0