From: Serge Pavlov Date: Tue, 28 Apr 2015 17:58:47 +0000 (+0000) Subject: Combine instantiation context of field initializer with context of class. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=59e3013d8496484e00bfd097713e95d1809f9226;p=clang Combine instantiation context of field initializer with context of class. Inclass initializer is instantiated in its own LocalInstantiationScope. It causes problems when instantiating local classes - when instantiation scope is searched for DeclContext of the field, the search fails. As a solution, the instantiation scope of field initializer is combined with its outer scope. This patch fixes PR23194. Differential Revision: http://reviews.llvm.org/D9258 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@236005 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaTemplateInstantiate.cpp b/lib/Sema/SemaTemplateInstantiate.cpp index eec13c581d..62b506276e 100644 --- a/lib/Sema/SemaTemplateInstantiate.cpp +++ b/lib/Sema/SemaTemplateInstantiate.cpp @@ -2233,7 +2233,7 @@ bool Sema::InstantiateInClassInitializer( EnterExpressionEvaluationContext EvalContext(*this, Sema::PotentiallyEvaluated); - LocalInstantiationScope Scope(*this); + LocalInstantiationScope Scope(*this, true); // Instantiate the initializer. ActOnStartCXXInClassMemberInitializer(); diff --git a/test/SemaTemplate/instantiate-local-class.cpp b/test/SemaTemplate/instantiate-local-class.cpp index c9897b9c61..367134a2a5 100644 --- a/test/SemaTemplate/instantiate-local-class.cpp +++ b/test/SemaTemplate/instantiate-local-class.cpp @@ -194,3 +194,22 @@ struct B { void f() { F(); } }; } + +namespace PR23194 { + struct X { + int operator()() const { return 0; } + }; + struct Y { + Y(int) {} + }; + template int make_seed_pair() noexcept { + struct state_t { + X x; + Y y{x()}; + }; + return 0; + } + int func() { + return make_seed_pair(); + } +}