Skip to content

Commit

Permalink
[clang-format] Handle template closer followed by braces (#110971)
Browse files Browse the repository at this point in the history
Fixes #110968.

(cherry picked from commit e5b05a5)
  • Loading branch information
owenca authored and tru committed Oct 15, 2024
1 parent 16c2aae commit 96839b6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
5 changes: 5 additions & 0 deletions clang/lib/Format/UnwrappedLineParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2131,6 +2131,11 @@ void UnwrappedLineParser::parseStructuralElement(
return;
}
break;
case tok::greater:
nextToken();
if (FormatTok->is(tok::l_brace))
FormatTok->Previous->setFinalizedType(TT_TemplateCloser);
break;
default:
nextToken();
break;
Expand Down
5 changes: 5 additions & 0 deletions clang/unittests/Format/TokenAnnotatorTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3399,6 +3399,11 @@ TEST_F(TokenAnnotatorTest, TemplateInstantiation) {
ASSERT_EQ(Tokens.size(), 11u) << Tokens;
EXPECT_TOKEN(Tokens[2], tok::less, TT_TemplateOpener);
EXPECT_TOKEN(Tokens[6], tok::greater, TT_TemplateCloser);

Tokens = annotate("return std::conditional_t<T::value == U::value, T, U>{};");
ASSERT_EQ(Tokens.size(), 21u) << Tokens;
EXPECT_TOKEN(Tokens[4], tok::less, TT_TemplateOpener);
EXPECT_TOKEN(Tokens[16], tok::greater, TT_TemplateCloser);
}

} // namespace
Expand Down

0 comments on commit 96839b6

Please sign in to comment.