[clang] ad24d2e - [clang] Don't assert on paren-less lambdas with dependent return type (#176296)
via cfe-commits
cfe-commits at lists.llvm.org
Sat Jan 17 07:43:56 PST 2026
Author: Nico Weber
Date: 2026-01-17T10:43:51-05:00
New Revision: ad24d2e9a5a9ea33dce43bf4223cd1ccad8fdcc9
URL: https://github.com/llvm/llvm-project/commit/ad24d2e9a5a9ea33dce43bf4223cd1ccad8fdcc9
DIFF: https://github.com/llvm/llvm-project/commit/ad24d2e9a5a9ea33dce43bf4223cd1ccad8fdcc9.diff
LOG: [clang] Don't assert on paren-less lambdas with dependent return type (#176296)
The initial implementation of C++23 style lambdas without parameter
lists, 0620e6f4b76a9, removed `DeclLoc`, which was used to intitialize
`DeclEndLoc`.
This code was then moved around a bit in behavior-preserving ways in
https://reviews.llvm.org/D124351 and 2eb1e75f42d7e09e.
If a lambda has no parentheses, no exception-specification,
attribute-specifier, *and* a decltype() return type (which leads to
`ParseTrailingReturnType` returning a range where
`Range.getEnd().isValid()` is false), then we no longer set a valid
`DeclEndLoc`. Fix this by restoring `DeclLoc` and using it as it was
used before 0620e6f4b76a9.
Fixes #176256.
Added:
Modified:
clang/lib/Parse/ParseExprCXX.cpp
clang/test/Parser/cxx2b-lambdas.cpp
Removed:
################################################################################
diff --git a/clang/lib/Parse/ParseExprCXX.cpp b/clang/lib/Parse/ParseExprCXX.cpp
index 7a5d28caf8521..842b52375eb14 100644
--- a/clang/lib/Parse/ParseExprCXX.cpp
+++ b/clang/lib/Parse/ParseExprCXX.cpp
@@ -1224,6 +1224,8 @@ ExprResult Parser::ParseLambdaExpressionAfterIntroducer(
Scope::FunctionPrototypeScope);
Actions.PushLambdaScope();
+ SourceLocation DeclLoc = Tok.getLocation();
+
Actions.ActOnLambdaExpressionAfterIntroducer(Intro, getCurScope());
ParsedAttributes Attributes(AttrFactory);
@@ -1308,7 +1310,7 @@ ExprResult Parser::ParseLambdaExpressionAfterIntroducer(
TypeResult TrailingReturnType;
SourceLocation TrailingReturnTypeLoc;
SourceLocation LParenLoc, RParenLoc;
- SourceLocation DeclEndLoc;
+ SourceLocation DeclEndLoc = DeclLoc;
bool HasParentheses = false;
bool HasSpecifiers = false;
SourceLocation MutableLoc;
diff --git a/clang/test/Parser/cxx2b-lambdas.cpp b/clang/test/Parser/cxx2b-lambdas.cpp
index 758ec9a42f56d..cda7f556691e6 100644
--- a/clang/test/Parser/cxx2b-lambdas.cpp
+++ b/clang/test/Parser/cxx2b-lambdas.cpp
@@ -27,6 +27,10 @@ auto L6 = [s = 1] mutable {};
auto L7 = [s = 1] constexpr mutable noexcept {}; // cxx11-error {{return type 'void' is not a literal type}}
#endif
auto L8 = [] -> bool { return true; };
+#if __cplusplus >= 201103L
+template <typename> struct PR176256 {};
+PR176256<void> token = [] -> decltype(token) { return {}; }();
+#endif
auto L9 = []<typename T> { return true; };
#if __cplusplus >= 201103L
auto L10 = []<typename T> noexcept { return true; };
More information about the cfe-commits
mailing list