https://github.com/jcsxky updated https://github.com/llvm/llvm-project/pull/85565
>From f6338c5674ad7ca9ad7595a6fbce2526fcc3f055 Mon Sep 17 00:00:00 2001 From: huqizhi <huqi...@feysh.com> Date: Sun, 17 Mar 2024 17:48:05 +0800 Subject: [PATCH] [Clang][Sema] Fix a crash in lambda instantiation --- clang/docs/ReleaseNotes.rst | 1 + .../lib/Sema/SemaTemplateInstantiateDecl.cpp | 4 ++++ clang/test/Sema/PR85343.cpp | 22 +++++++++++++++++++ 3 files changed, 27 insertions(+) create mode 100644 clang/test/Sema/PR85343.cpp 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..7786557396cd13 100644 --- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp +++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp @@ -5182,6 +5182,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..20e618482e4d86 --- /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; } _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits