[PATCH] D116553: [clang-format] Fix incorrect formatting of lambdas inside brace initialisation when the return type has square brackets `[]`.
Marek Kurdej via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Jan 3 12:35:01 PST 2022
curdeius created this revision.
curdeius added reviewers: MyDeveloperDay, HazardyKnusperkeks, owenpan.
curdeius requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
Fixes https://github.com/llvm/llvm-project/issues/52943.
Before:
namespace ns {
void foo() {
std::variant<int, double> v;
std::visit(overloaded{[](auto &&) -> int (*)[] { return nullptr; }}, v);
}
} // namespace ns
got formatted as:
namespace ns {
void foo() {
std::variant<int, double> v;
std::visit(overloaded{[](auto &&) -> int (*)[] { return nullptr;
}
} // namespace ns
, v);
}
} // namespace ns
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D116553
Files:
clang/lib/Format/UnwrappedLineParser.cpp
clang/unittests/Format/FormatTest.cpp
Index: clang/unittests/Format/FormatTest.cpp
===================================================================
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -20232,6 +20232,10 @@
"};");
verifyFormat("[]() -> Void<T...> {};");
verifyFormat("[a, b]() -> Tuple<T...> { return {}; };");
+ verifyFormat("SomeFunction({[]() -> int[] { return {}; }});");
+ verifyFormat("SomeFunction({[]() -> int *[] { return {}; }});");
+ verifyFormat("SomeFunction({[]() -> int (*)[] { return {}; }});");
+ verifyFormat("SomeFunction({[]() -> ns::type<int (*)[]> { return {}; }});");
// Lambdas with explicit template argument lists.
verifyFormat(
Index: clang/lib/Format/UnwrappedLineParser.cpp
===================================================================
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -1786,6 +1786,9 @@
case tok::l_paren:
parseParens();
break;
+ case tok::l_square:
+ parseSquare();
+ break;
case tok::amp:
case tok::star:
case tok::kw_const:
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D116553.397122.patch
Type: text/x-patch
Size: 1119 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220103/3725cdb0/attachment.bin>
More information about the cfe-commits
mailing list