Skip to content

Commit 212e444

Browse files
committed
add test case
1 parent 1caf823 commit 212e444

File tree

3 files changed

+24
-4
lines changed

3 files changed

+24
-4
lines changed

clang/lib/Format/ContinuationIndenter.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -406,8 +406,8 @@ bool ContinuationIndenter::mustBreak(const LineState &State) {
406406
}
407407
if (CurrentState.BreakBeforeClosingParen && Current.is(tok::r_paren))
408408
return true;
409-
if (CurrentState.BreakBeforeClosingAngle &&
410-
Current.ClosesTemplateDeclaration && Style.BreakBeforeTemplateClose) {
409+
if (CurrentState.BreakBeforeClosingAngle && Current.is(TT_TemplateCloser) &&
410+
Style.BreakBeforeTemplateClose) {
411411
return true;
412412
}
413413
if (Style.Language == FormatStyle::LK_ObjC &&
@@ -1377,7 +1377,7 @@ unsigned ContinuationIndenter::getNewLineColumn(const LineState &State) {
13771377
State.Stack.size() > 1) {
13781378
return State.Stack[State.Stack.size() - 2].LastSpace;
13791379
}
1380-
if (Current.ClosesTemplateDeclaration && Style.BreakBeforeTemplateClose &&
1380+
if (Current.is(TT_TemplateCloser) && Style.BreakBeforeTemplateClose &&
13811381
State.Stack.size() > 1) {
13821382
return State.Stack[State.Stack.size() - 2].LastSpace;
13831383
}

clang/lib/Format/TokenAnnotator.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6254,7 +6254,7 @@ bool TokenAnnotator::canBreakBefore(const AnnotatedLine &Line,
62546254
return false;
62556255

62566256
if (Right.is(TT_TemplateCloser))
6257-
return Right.ClosesTemplateDeclaration && Style.BreakBeforeTemplateClose;
6257+
return Style.BreakBeforeTemplateClose;
62586258
if (Right.is(tok::r_square) && Right.MatchingParen &&
62596259
Right.MatchingParen->is(TT_LambdaLSquare)) {
62606260
return false;

clang/unittests/Format/FormatTest.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11154,6 +11154,26 @@ TEST_F(FormatTest, BreakBeforeTemplateClose) {
1115411154
"};",
1115511155
Style);
1115611156

11157+
// test from issue #80049
11158+
verifyFormat(
11159+
"void foo() {\n"
11160+
" using type = std::remove_cv_t<\n"
11161+
" add_common_cv_reference<\n"
11162+
" std::common_type_t<std::decay_t<T0>, std::decay_t<T1>>,\n"
11163+
" T0,\n"
11164+
" T1\n"
11165+
" >\n"
11166+
" >;\n"
11167+
"}\n",
11168+
"void foo() {\n"
11169+
" using type = std::remove_cv_t<\n"
11170+
" add_common_cv_reference<\n"
11171+
" std::common_type_t<std::decay_t<T0>, std::decay_t<T1>>,\n"
11172+
" T0,\n"
11173+
" T1>>;\n"
11174+
"}\n",
11175+
Style);
11176+
1115711177
// now test that it handles the cases when the column limit forces wrapping
1115811178
Style.ColumnLimit = 40;
1115911179
// when the column limit allows it, the template should be combined back into

0 commit comments

Comments
 (0)