[llvm-branch-commits] [clang] 592367a - [clang-format] regression from clang-format v13
Tom Stellard via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Mon Feb 7 13:22:44 PST 2022
Author: mydeveloperday
Date: 2022-02-07T13:20:56-08:00
New Revision: 592367ab7ea8c70eb26f2a6a7ddeb05b50322545
URL: https://github.com/llvm/llvm-project/commit/592367ab7ea8c70eb26f2a6a7ddeb05b50322545
DIFF: https://github.com/llvm/llvm-project/commit/592367ab7ea8c70eb26f2a6a7ddeb05b50322545.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
(cherry picked from commit 23fc20e06c088acff81a06ad546a848bee083051)
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 6426791284090..2e2293c6d58bd 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -3102,7 +3102,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 005e2d6a7b559..136a25fa89468 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -23638,6 +23638,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) {
More information about the llvm-branch-commits
mailing list