[PATCH] D118220: [clang-format] Correctly format lambdas with variadic template parameters.
Marek Kurdej via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Jan 26 07:11:10 PST 2022
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG93948c5299d7: [clang-format] Correctly format lambdas with variadic template parameters. (authored by curdeius).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D118220/new/
https://reviews.llvm.org/D118220
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
@@ -20560,6 +20560,36 @@
// Lambdas with explicit template argument lists.
verifyFormat(
"auto L = []<template <typename> class T, class U>(T<U> &&a) {};\n");
+ verifyFormat("auto L = []<class T>(T) {\n"
+ " {\n"
+ " f();\n"
+ " g();\n"
+ " }\n"
+ "};\n");
+ verifyFormat("auto L = []<class... T>(T...) {\n"
+ " {\n"
+ " f();\n"
+ " g();\n"
+ " }\n"
+ "};\n");
+ verifyFormat("auto L = []<typename... T>(T...) {\n"
+ " {\n"
+ " f();\n"
+ " g();\n"
+ " }\n"
+ "};\n");
+ verifyFormat("auto L = []<template <typename...> class T>(T...) {\n"
+ " {\n"
+ " f();\n"
+ " g();\n"
+ " }\n"
+ "};\n");
+ verifyFormat("auto L = []</*comment*/ class... T>(T...) {\n"
+ " {\n"
+ " f();\n"
+ " g();\n"
+ " }\n"
+ "};\n");
// Multiple lambdas in the same parentheses change indentation rules. These
// lambdas are forced to start on new lines.
Index: clang/lib/Format/UnwrappedLineParser.cpp
===================================================================
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -1856,6 +1856,7 @@
return false;
bool SeenArrow = false;
+ bool InTemplateParameterList = false;
while (FormatTok->isNot(tok::l_brace)) {
if (FormatTok->isSimpleTypeSpecifier()) {
@@ -1871,6 +1872,14 @@
case tok::l_square:
parseSquare();
break;
+ case tok::kw_class:
+ case tok::kw_template:
+ case tok::kw_typename:
+ assert(FormatTok->Previous);
+ if (FormatTok->Previous->is(tok::less))
+ InTemplateParameterList = true;
+ nextToken();
+ break;
case tok::amp:
case tok::star:
case tok::kw_const:
@@ -1880,11 +1889,8 @@
case tok::identifier:
case tok::numeric_constant:
case tok::coloncolon:
- case tok::kw_class:
case tok::kw_mutable:
case tok::kw_noexcept:
- case tok::kw_template:
- case tok::kw_typename:
nextToken();
break;
// Specialization of a template with an integer parameter can contain
@@ -1921,7 +1927,7 @@
case tok::ellipsis:
case tok::kw_true:
case tok::kw_false:
- if (SeenArrow) {
+ if (SeenArrow || InTemplateParameterList) {
nextToken();
break;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D118220.403260.patch
Type: text/x-patch
Size: 2814 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220126/ec2231f0/attachment.bin>
More information about the cfe-commits
mailing list