summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormydeveloperday <mydeveloperday@gmail.com>2022-01-10 08:28:42 +0000
committermydeveloperday <mydeveloperday@gmail.com>2022-01-10 08:29:35 +0000
commit5c2e7c9ca043d92bed75b08e653fb47c384edd13 (patch)
treea9702208600a507a2436459f9964456b8fe6c1db
parent5ff916ab72b26e667bd5d2e4a762650ba479c781 (diff)
downloadllvm-5c2e7c9ca043d92bed75b08e653fb47c384edd13.tar.gz
[clang-format] Ensure we can correctly parse lambda in the template argument list
https://github.com/llvm/llvm-project/issues/46505 The presence of a lambda in an argument template list ignored the [] as a lambda at all, this caused the contents of the <> to be incorrectly analyzed. ``` struct Y : X < [] { return 0; } > {}; ``` Fixes: #46505 Reviewed By: curdeius Differential Revision: https://reviews.llvm.org/D116806
-rw-r--r--clang/lib/Format/UnwrappedLineParser.cpp2
-rw-r--r--clang/unittests/Format/FormatTest.cpp9
2 files changed, 11 insertions, 0 deletions
diff --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp
index c293c236193c..410cce79a087 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -2874,6 +2874,8 @@ void UnwrappedLineParser::parseRecord(bool ParseAsExpr) {
if (!tryToParseBracedList())
break;
}
+ if (FormatTok->is(tok::l_square) && !tryToParseLambda())
+ break;
if (FormatTok->Tok.is(tok::semi))
return;
if (Style.isCSharp() && FormatTok->is(Keywords.kw_where)) {
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index 85ce3171bbc8..d3e4479a5aa8 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -23212,6 +23212,15 @@ TEST_F(FormatTest, EmptyShortBlock) {
Style);
}
+TEST_F(FormatTest, ShortTemplatedArgumentLists) {
+ auto Style = getLLVMStyle();
+
+ verifyFormat("struct Y : X<[] { return 0; }> {};", Style);
+ verifyFormat("struct Y<[] { return 0; }> {};", Style);
+
+ verifyFormat("struct Z : X<decltype([] { return 0; }){}> {};", Style);
+}
+
} // namespace
} // namespace format
} // namespace clang