diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 6f97acc09bc93..dc7569cf79f43 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -234,6 +234,10 @@ Bug Fixes to C++ Support and appear in an implicit cast. (`#64949 `_). +- Fix crash when parsing ill-formed lambda trailing return type. Fixes: + (`#64962 `_) and + (`#28679 `_). + Bug Fixes to AST Handling ^^^^^^^^^^^^^^^^^^^^^^^^^ - Fixed an import failure of recursive friend class template. diff --git a/clang/lib/Parse/ParseExprCXX.cpp b/clang/lib/Parse/ParseExprCXX.cpp index 678ecad19ecd8..d2715db95f528 100644 --- a/clang/lib/Parse/ParseExprCXX.cpp +++ b/clang/lib/Parse/ParseExprCXX.cpp @@ -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()); diff --git a/clang/test/Parser/cxx2a-template-lambdas.cpp b/clang/test/Parser/cxx2a-template-lambdas.cpp index 5cf1a862d878c..98c74a247b535 100644 --- a/clang/test/Parser/cxx2a-template-lambdas.cpp +++ b/clang/test/Parser/cxx2a-template-lambdas.cpp @@ -32,3 +32,11 @@ auto XL1 = [] 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() { + [] (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'}} +} +} diff --git a/clang/test/SemaCXX/subst-func-type-invalid-ret-type.cpp b/clang/test/SemaCXX/subst-func-type-invalid-ret-type.cpp index c78ffff3ff50e..565e06b101a7b 100644 --- a/clang/test/SemaCXX/subst-func-type-invalid-ret-type.cpp +++ b/clang/test/SemaCXX/subst-func-type-invalid-ret-type.cpp @@ -5,12 +5,11 @@ template T declval(); template -auto Call(T x) -> decltype(declval()(0)) {} // expected-note{{candidate template ignored}} +auto Call(T x) -> decltype(declval()(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'}} }