[PATCH] D140312: [clang-format] Disallow decltype in the middle of constraints
Emilia Dreamer via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Dec 19 09:14:53 PST 2022
rymiel created this revision.
rymiel added reviewers: HazardyKnusperkeks, owenpan, MyDeveloperDay.
Herald added a project: All.
rymiel requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
If a function with a `requires` clause as a constraint has a decltype
return type, such as `decltype(auto)`, the decltype was seen to be part
of the constraint clause, rather than as part of the function
declaration, causing it to be placed on the wrong line.
This patch disallows decltype to be a part of these clauses
Fixes https://github.com/llvm/llvm-project/issues/59578
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D140312
Files:
clang/lib/Format/UnwrappedLineParser.cpp
clang/unittests/Format/FormatTest.cpp
clang/unittests/Format/TokenAnnotatorTest.cpp
Index: clang/unittests/Format/TokenAnnotatorTest.cpp
===================================================================
--- clang/unittests/Format/TokenAnnotatorTest.cpp
+++ clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -580,6 +580,14 @@
EXPECT_TRUE(Tokens[9]->ClosesRequiresClause);
EXPECT_TOKEN(Tokens[11], tok::identifier, TT_FunctionDeclarationName);
+ Tokens = annotate("template <typename T>\n"
+ "requires Bar<T>\n"
+ "decltype(auto) foo(T) { return false; }");
+ ASSERT_EQ(Tokens.size(), 24u) << Tokens;
+ EXPECT_TOKEN(Tokens[5], tok::kw_requires, TT_RequiresClause);
+ EXPECT_TRUE(Tokens[9]->ClosesRequiresClause);
+ EXPECT_TOKEN(Tokens[14], tok::identifier, TT_FunctionDeclarationName);
+
Tokens = annotate("template <typename T>\n"
"struct S {\n"
" void foo() const requires Bar<T>;\n"
Index: clang/unittests/Format/FormatTest.cpp
===================================================================
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -24199,6 +24199,10 @@
" }\n"
"};");
+ verifyFormat("template <class T>\n"
+ " requires(std::same_as<int, T>)\n"
+ "decltype(auto) fun() {}");
+
auto Style = getLLVMStyle();
verifyFormat(
Index: clang/lib/Format/UnwrappedLineParser.cpp
===================================================================
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -3560,7 +3560,6 @@
case tok::minus:
case tok::star:
case tok::slash:
- case tok::kw_decltype:
LambdaNextTimeAllowed = true;
// Just eat them.
nextToken();
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D140312.483983.patch
Type: text/x-patch
Size: 1761 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20221219/56419cb6/attachment.bin>
More information about the cfe-commits
mailing list