diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 45234c316eba8..401128f06b982 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -366,6 +366,7 @@ Bug Fixes to C++ Support - Fixed a crash when `explicit(bool)` is used with an incomplete enumeration. (#GH183887) - Fixed a crash on ``typeid`` of incomplete local types during template instantiation. (#GH63242), (#GH176397) - Fixed a crash when an immediate-invoked ``consteval`` lambda is used as an invalid initializer. (#GH185270) +- Fixed a crash when a lambda expression capturing local array is used in an invalid template constructor. (#GH187183) - Fixed an assertion failure when using a global destructor with a target with a non-default program address space. (#GH186484) - Inherited constructors in ``dllexport`` classes are now exported for ABI-compatible cases, matching diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp index 5553f25546c38..666ecc403c3cd 100644 --- a/clang/lib/Sema/SemaExprCXX.cpp +++ b/clang/lib/Sema/SemaExprCXX.cpp @@ -7812,8 +7812,15 @@ ExprResult Sema::ActOnFinishFullExpr(Expr *FE, SourceLocation CC, while (isa_and_nonnull(DC)) DC = DC->getParent(); const bool IsInLambdaDeclContext = isLambdaCallOperator(DC); + + // Do not check for potential captures if the function in which the lambda + // is defined does not have a valid decl. (GH187183) + FunctionDecl *FD = getCurFunctionDecl(); + bool IsValidParentFunc = !FD || !FD->isInvalidDecl(); + if (IsInLambdaDeclContext && CurrentLSI && - CurrentLSI->hasPotentialCaptures() && !FullExpr.isInvalid()) + CurrentLSI->hasPotentialCaptures() && !FullExpr.isInvalid() && + IsValidParentFunc) CheckIfAnyEnclosingLambdasMustCaptureAnyPotentialCaptures(FE, CurrentLSI, *this); return MaybeCreateExprWithCleanups(FullExpr); diff --git a/clang/test/SemaCXX/GH187183.cpp b/clang/test/SemaCXX/GH187183.cpp new file mode 100644 index 0000000000000..90323bccb2f51 --- /dev/null +++ b/clang/test/SemaCXX/GH187183.cpp @@ -0,0 +1,16 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s + +namespace GH187183 { + template + struct S { + S(); + }; + + using X = S<0>; + + template // expected-error {{template parameter list matching the non-templated nested type 'GH187183::S<0>' should be empty ('template<>')}} + S<0>::S() { + int e[1]; + test([&e]() { return e[0]; }); + } +}