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. http://reviews.llvm.org/D9258 Files: lib/Sema/SemaTemplateInstantiate.cpp test/SemaTemplate/instantiate-local-class.cpp Index: lib/Sema/SemaTemplateInstantiate.cpp =================================================================== --- lib/Sema/SemaTemplateInstantiate.cpp +++ lib/Sema/SemaTemplateInstantiate.cpp @@ -2241,7 +2241,7 @@ EnterExpressionEvaluationContext EvalContext(*this, Sema::PotentiallyEvaluated); - LocalInstantiationScope Scope(*this); + LocalInstantiationScope Scope(*this, true); // Instantiate the initializer. ActOnStartCXXInClassMemberInitializer(); Index: test/SemaTemplate/instantiate-local-class.cpp =================================================================== --- test/SemaTemplate/instantiate-local-class.cpp +++ test/SemaTemplate/instantiate-local-class.cpp @@ -194,3 +194,22 @@ void f() { F<int>(); } }; } + +namespace PR23194 { + struct X { + int operator()() const { return 0; } + }; + struct Y { + Y(int) {} + }; + template <bool = true> int make_seed_pair() noexcept { + struct state_t { + X x; + Y y{x()}; + }; + return 0; + } + int func() { + return make_seed_pair(); + } +} EMAIL PREFERENCES http://reviews.llvm.org/settings/panel/emailpreferences/
Index: lib/Sema/SemaTemplateInstantiate.cpp =================================================================== --- lib/Sema/SemaTemplateInstantiate.cpp +++ lib/Sema/SemaTemplateInstantiate.cpp @@ -2241,7 +2241,7 @@ EnterExpressionEvaluationContext EvalContext(*this, Sema::PotentiallyEvaluated); - LocalInstantiationScope Scope(*this); + LocalInstantiationScope Scope(*this, true); // Instantiate the initializer. ActOnStartCXXInClassMemberInitializer(); Index: test/SemaTemplate/instantiate-local-class.cpp =================================================================== --- test/SemaTemplate/instantiate-local-class.cpp +++ test/SemaTemplate/instantiate-local-class.cpp @@ -194,3 +194,22 @@ void f() { F<int>(); } }; } + +namespace PR23194 { + struct X { + int operator()() const { return 0; } + }; + struct Y { + Y(int) {} + }; + template <bool = true> int make_seed_pair() noexcept { + struct state_t { + X x; + Y y{x()}; + }; + return 0; + } + int func() { + return make_seed_pair(); + } +}
_______________________________________________ cfe-commits mailing list cfe-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits