diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index e6e33e7a9a280..20d950cac9579 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -429,6 +429,8 @@ Bug Fixes in This Version - Fixed a failed assertion with empty filename arguments in ``__has_embed``. (#GH159898) - Fixed a failed assertion with empty filename in ``#embed`` directive. (#GH162951) - Fixed a crash triggered by unterminated ``__has_embed``. (#GH162953) +- Fixed a wrong diagnostic about a local variable inside a lambda in unevaluated + context needs capture. (#GH163837) Bug Fixes to Compiler Builtins ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp index 28925cca8f956..439a5317f06f1 100644 --- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp +++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp @@ -7061,8 +7061,15 @@ NamedDecl *Sema::FindInstantiatedDecl(SourceLocation Loc, NamedDecl *D, // anonymous unions in class templates). } - if (!ParentDependsOnArgs) + if (!ParentDependsOnArgs) { + if (auto Found = + CurrentInstantiationScope + ? CurrentInstantiationScope->getInstantiationOfIfExists(D) + : nullptr) { + return cast(Found->dyn_cast()); + } return D; + } ParentDC = FindInstantiatedContext(Loc, ParentDC, TemplateArgs); if (!ParentDC) diff --git a/clang/test/SemaCXX/lambda-unevaluated.cpp b/clang/test/SemaCXX/lambda-unevaluated.cpp index 9289fc9ec1243..4b0e1abdb38f0 100644 --- a/clang/test/SemaCXX/lambda-unevaluated.cpp +++ b/clang/test/SemaCXX/lambda-unevaluated.cpp @@ -282,3 +282,22 @@ static_assert(__is_same_as(int, helper)); } // namespace GH138018 + +namespace GH163837 { + +template +void f(); + +template +struct X { + using type = decltype([](auto) { + f<[]{ + int result = 0; + return result; + }()>(); + }(0)); +}; + +X l; + +} // namespace GH163837