[PATCH] D158808: [Clang] Modify Parser::ParseLambdaExpressionAfterIntroducer to check whether the lambda-declarator is valid

Shafik Yaghmour via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Aug 29 11:31:24 PDT 2023


This revision was automatically updated to reflect the committed changes.
Closed by commit rG6f30ef360127: [Clang] Modify Parser::ParseLambdaExpressionAfterIntroducer to check whether… (authored by shafik).
Herald added a project: clang.

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D158808/new/

https://reviews.llvm.org/D158808

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Parse/ParseExprCXX.cpp
  clang/test/Parser/cxx2a-template-lambdas.cpp
  clang/test/SemaCXX/subst-func-type-invalid-ret-type.cpp


Index: clang/test/SemaCXX/subst-func-type-invalid-ret-type.cpp
===================================================================
--- clang/test/SemaCXX/subst-func-type-invalid-ret-type.cpp
+++ clang/test/SemaCXX/subst-func-type-invalid-ret-type.cpp
@@ -5,12 +5,11 @@
 template<typename T> T declval();
 
 template <typename T>
-auto Call(T x) -> decltype(declval<T>()(0)) {} // expected-note{{candidate template ignored}}
+auto Call(T x) -> decltype(declval<T>()(0)) {}
 
 class Status {};
 
 void fun() {
   // The Status() (instead of Status) here used to cause a crash.
   Call([](auto x) -> Status() {}); // expected-error{{function cannot return function type 'Status ()}}
-  // expected-error at -1{{no matching function for call to 'Call'}}
 }
Index: clang/test/Parser/cxx2a-template-lambdas.cpp
===================================================================
--- clang/test/Parser/cxx2a-template-lambdas.cpp
+++ clang/test/Parser/cxx2a-template-lambdas.cpp
@@ -32,3 +32,11 @@
 // expected-warning at -3 {{is a C++23 extension}}
 // expected-warning at -3 {{is a C++23 extension}}
 #endif
+
+namespace GH64962 {
+void f() {
+  [] <typename T>(T i) -> int[] // expected-error {{function cannot return array type 'int[]'}}
+                                // extension-warning {{explicit template parameter list for lambdas is a C++20 extension}}
+    { return 3; } (v); // expected-error {{use of undeclared identifier 'v'}}
+}
+}
Index: clang/lib/Parse/ParseExprCXX.cpp
===================================================================
--- clang/lib/Parse/ParseExprCXX.cpp
+++ clang/lib/Parse/ParseExprCXX.cpp
@@ -1546,7 +1546,8 @@
   TemplateParamScope.Exit();
   LambdaScope.Exit();
 
-  if (!Stmt.isInvalid() && !TrailingReturnType.isInvalid())
+  if (!Stmt.isInvalid() && !TrailingReturnType.isInvalid() &&
+      !D.isInvalidType())
     return Actions.ActOnLambdaExpr(LambdaBeginLoc, Stmt.get(), getCurScope());
 
   Actions.ActOnLambdaError(LambdaBeginLoc, getCurScope());
Index: clang/docs/ReleaseNotes.rst
===================================================================
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -234,6 +234,10 @@
   and appear in an implicit cast.
   (`#64949 <https://github.com/llvm/llvm-project/issues/64949>`_).
 
+- Fix crash when parsing ill-formed lambda trailing return type. Fixes:
+  (`#64962 <https://github.com/llvm/llvm-project/issues/64962>`_) and
+  (`#28679 <https://github.com/llvm/llvm-project/issues/28679>`_).
+
 Bug Fixes to AST Handling
 ^^^^^^^^^^^^^^^^^^^^^^^^^
 - Fixed an import failure of recursive friend class template.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D158808.554445.patch
Type: text/x-patch
Size: 2610 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230829/39b8011b/attachment.bin>


More information about the cfe-commits mailing list