Skip to content

Commit 592367a

Browse files
mydeveloperdaytstellar
authored andcommitted
[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 (cherry picked from commit 23fc20e)
1 parent ec05ccb commit 592367a

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
@@ -3102,7 +3102,8 @@ void UnwrappedLineParser::parseRecord(bool ParseAsExpr) {
31023102
}
31033103
if (FormatTok->is(tok::l_square)) {
31043104
FormatToken *Previous = FormatTok->Previous;
3105-
if (!Previous || Previous->isNot(tok::r_paren)) {
3105+
if (!Previous ||
3106+
!(Previous->is(tok::r_paren) || Previous->isTypeOrIdentifier())) {
31063107
// Don't try parsing a lambda if we had a closing parenthesis before,
31073108
// it was probably a pointer to an array: int (*)[].
31083109
if (!tryToParseLambda())

clang/unittests/Format/FormatTest.cpp

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

2364023640
verifyFormat("struct Z : X<decltype([] { return 0; }){}> {};", Style);
23641+
verifyFormat("template <int N> struct Foo<char[N]> {};", Style);
2364123642
}
2364223643

2364323644
TEST_F(FormatTest, RemoveBraces) {

0 commit comments

Comments
 (0)