llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-clang Author: Qizhi Hu (jcsxky) <details> <summary>Changes</summary> Fix https://github.com/llvm/llvm-project/issues/85343 When build lambda expression in lambda instantiation, `ThisType` is required in `Sema::BuildCaptureInit`. Set it in `Sema::InstantiateFunctionDefinition` when build capture of lambda and it will be used later in lambda expression transformation. --- Full diff: https://github.com/llvm/llvm-project/pull/85565.diff 3 Files Affected: - (modified) clang/docs/ReleaseNotes.rst (+1) - (modified) clang/lib/Sema/SemaTemplateInstantiateDecl.cpp (+7) - (added) clang/test/Sema/PR85343.cpp (+22) ``````````diff diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index ba9de1ac98de08..26a87e9ab7b066 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -392,6 +392,7 @@ Bug Fixes to C++ Support Fixes (#GH84368). - Fixed a crash while checking constraints of a trailing requires-expression of a lambda, that the expression references to an entity declared outside of the lambda. (#GH64808) +- Fix a crash in lambda instantiation that missing set ``ThisType`` when checking capture. Fixes (#GH85343). Bug Fixes to AST Handling ^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp index dc972018e7b281..dcfb1798d69641 100644 --- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp +++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp @@ -13,12 +13,14 @@ #include "clang/AST/ASTConsumer.h" #include "clang/AST/ASTContext.h" #include "clang/AST/ASTMutationListener.h" +#include "clang/AST/DeclCXX.h" #include "clang/AST/DeclTemplate.h" #include "clang/AST/DeclVisitor.h" #include "clang/AST/DependentDiagnostic.h" #include "clang/AST/Expr.h" #include "clang/AST/ExprCXX.h" #include "clang/AST/PrettyDeclStackTrace.h" +#include "clang/AST/Type.h" #include "clang/AST/TypeLoc.h" #include "clang/Basic/SourceManager.h" #include "clang/Basic/TargetInfo.h" @@ -29,6 +31,7 @@ #include "clang/Sema/SemaInternal.h" #include "clang/Sema/Template.h" #include "clang/Sema/TemplateInstCallback.h" +#include "llvm/Support/Casting.h" #include "llvm/Support/TimeProfiler.h" #include <optional> @@ -5182,6 +5185,10 @@ void Sema::InstantiateFunctionDefinition(SourceLocation PointOfInstantiation, // Enter the scope of this instantiation. We don't use // PushDeclContext because we don't have a scope. Sema::ContextRAII savedContext(*this, Function); + // We need ThisType in lambda instantiation. + Sema::CXXThisScopeRAII ThisScope( + *this, dyn_cast<CXXRecordDecl>(Function->getDeclContext()), + Qualifiers()); FPFeaturesStateRAII SavedFPFeatures(*this); CurFPFeatures = FPOptions(getLangOpts()); diff --git a/clang/test/Sema/PR85343.cpp b/clang/test/Sema/PR85343.cpp new file mode 100644 index 00000000000000..aa598a5df400bd --- /dev/null +++ b/clang/test/Sema/PR85343.cpp @@ -0,0 +1,22 @@ +// RUN: %clang_cc1 -std=c++11 -verify %s +// expected-no-diagnostics + +template <typename c> auto ab() -> c ; + +template <typename> struct e {}; + +template <typename f> struct ac { + template <typename h> static e<decltype(ab<h>()(ab<int>))> i; + decltype(i<f>) j; +}; + +struct d { + template <typename f> + d(f) { + ac<f> a; + } +}; +struct a { + d b = [=](auto) { (void)[this] {}; }; +}; +void b() { new a; } \ No newline at end of file `````````` </details> https://github.com/llvm/llvm-project/pull/85565 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits