Author: mydeveloperday Date: 2022-02-03T18:37:43Z New Revision: 23fc20e06c088acff81a06ad546a848bee083051
URL: https://github.com/llvm/llvm-project/commit/23fc20e06c088acff81a06ad546a848bee083051 DIFF: https://github.com/llvm/llvm-project/commit/23fc20e06c088acff81a06ad546a848bee083051.diff LOG: [clang-format] regression from clang-format v13 https://github.com/llvm/llvm-project/issues/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 https://github.com/llvm/llvm-project/commit/5c2e7c9ca043d92bed75b08e653fb47c384edd13 Reviewed By: curdeius Differential Revision: https://reviews.llvm.org/D118911 Added: Modified: clang/lib/Format/UnwrappedLineParser.cpp clang/unittests/Format/FormatTest.cpp Removed: ################################################################################ diff --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp index 37fad4d9f49d..eb927b5c4921 100644 --- a/clang/lib/Format/UnwrappedLineParser.cpp +++ b/clang/lib/Format/UnwrappedLineParser.cpp @@ -3057,7 +3057,8 @@ void UnwrappedLineParser::parseRecord(bool ParseAsExpr) { } if (FormatTok->is(tok::l_square)) { FormatToken *Previous = FormatTok->Previous; - if (!Previous || Previous->isNot(tok::r_paren)) { + if (!Previous || + !(Previous->is(tok::r_paren) || Previous->isTypeOrIdentifier())) { // Don't try parsing a lambda if we had a closing parenthesis before, // it was probably a pointer to an array: int (*)[]. if (!tryToParseLambda()) diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index 094b9142aa10..96efc0e029e0 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -23665,6 +23665,7 @@ TEST_F(FormatTest, ShortTemplatedArgumentLists) { verifyFormat("struct Y<[] { return 0; }> {};", Style); verifyFormat("struct Z : X<decltype([] { return 0; }){}> {};", Style); + verifyFormat("template <int N> struct Foo<char[N]> {};", Style); } TEST_F(FormatTest, RemoveBraces) { _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits