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

We had a couple of crashes due to invalid lambda trailing return types that
were diagnosed but not treated as errors during parsing. So now in
Parser::ParseLambdaExpressionAfterIntroducer(...) after ActOnStartOfLambdaDefinition(...)
we also check if the lambda-declarator is invalid and if so we end up in ActOnLambdaError(...).

Fixes: https://github.com/llvm/llvm-project/issues/64962
https://github.com/llvm/llvm-project/issues/28679

Differential Revision: https://reviews.llvm.org/D158808
This commit is contained in:
Shafik Yaghmour 2023-08-29 11:28:57 -07:00
parent b26bb30b46
commit 6f30ef3601
4 changed files with 15 additions and 3 deletions

View File

@ -234,6 +234,10 @@ Bug Fixes to C++ Support
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.

View File

@ -1546,7 +1546,8 @@ ExprResult Parser::ParseLambdaExpressionAfterIntroducer(
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());

View File

@ -32,3 +32,11 @@ auto XL1 = []<auto> requires true noexcept requires true {}; // expected-error {
// expected-warning@-3 {{is a C++23 extension}}
// expected-warning@-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'}}
}
}

View File

@ -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@-1{{no matching function for call to 'Call'}}
}