Skip to content

Commit 23fc20e

Browse files
[clang-format] regression from clang-format v13
#53567 The following source ``` namespace A { template <int N> struct Foo<char[N]> { void foo() { std::cout << "Bar"; } }; // namespace A ``` is incorrectly formatted as: ``` namespace A { template <int N> struct Foo<char[N]>{void foo(){std::cout << "Bar"; } } ; // namespace A ``` This looks to be caused by 5c2e7c9 Reviewed By: curdeius Differential Revision: https://reviews.llvm.org/D118911
1 parent ffea9fc commit 23fc20e

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

clang/lib/Format/UnwrappedLineParser.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3057,7 +3057,8 @@ void UnwrappedLineParser::parseRecord(bool ParseAsExpr) {
30573057
}
30583058
if (FormatTok->is(tok::l_square)) {
30593059
FormatToken *Previous = FormatTok->Previous;
3060-
if (!Previous || Previous->isNot(tok::r_paren)) {
3060+
if (!Previous ||
3061+
!(Previous->is(tok::r_paren) || Previous->isTypeOrIdentifier())) {
30613062
// Don't try parsing a lambda if we had a closing parenthesis before,
30623063
// it was probably a pointer to an array: int (*)[].
30633064
if (!tryToParseLambda())

clang/unittests/Format/FormatTest.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23665,6 +23665,7 @@ TEST_F(FormatTest, ShortTemplatedArgumentLists) {
2366523665
verifyFormat("struct Y<[] { return 0; }> {};", Style);
2366623666

2366723667
verifyFormat("struct Z : X<decltype([] { return 0; }){}> {};", Style);
23668+
verifyFormat("template <int N> struct Foo<char[N]> {};", Style);
2366823669
}
2366923670

2367023671
TEST_F(FormatTest, RemoveBraces) {

0 commit comments

Comments
 (0)