https://github.com/nico created https://github.com/llvm/llvm-project/pull/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.

>From aa79e27ae37ef514172896bbcb411e5d39f5a67b Mon Sep 17 00:00:00 2001
From: Nico Weber <[email protected]>
Date: Thu, 15 Jan 2026 20:49:01 -0500
Subject: [PATCH] [clang] Don't assert on paren-less lambdas with dependent
 return type

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.
---
 clang/lib/Parse/ParseExprCXX.cpp    | 4 +++-
 clang/test/Parser/cxx2b-lambdas.cpp | 4 ++++
 2 files changed, 7 insertions(+), 1 deletion(-)

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; };

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to