llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-clang Author: Kartik (hax0kartik) <details> <summary>Changes</summary> Fix by preventing the check for potential captures if the function in which the lambda is defined has an invalid decl. Fixes #<!-- -->187183. --- Full diff: https://github.com/llvm/llvm-project/pull/187676.diff 3 Files Affected: - (modified) clang/docs/ReleaseNotes.rst (+1) - (modified) clang/lib/Sema/SemaExprCXX.cpp (+7-1) - (added) clang/test/SemaCXX/GH187183.cpp (+16) ``````````diff 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..37b97a5bf9bc4 100644 --- a/clang/lib/Sema/SemaExprCXX.cpp +++ b/clang/lib/Sema/SemaExprCXX.cpp @@ -7812,8 +7812,14 @@ ExprResult Sema::ActOnFinishFullExpr(Expr *FE, SourceLocation CC, while (isa_and_nonnull<CapturedDecl>(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..667ee98bb7180 --- /dev/null +++ b/clang/test/SemaCXX/GH187183.cpp @@ -0,0 +1,16 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s + +namespace GH187183 { + template<int T> + struct S { + S(); + }; + + using X = S<0>; + + template<int T> // 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]; }); + } +} `````````` </details> https://github.com/llvm/llvm-project/pull/187676 _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
