From f5ba7e089daadcd60b0f6e31d932be8bb6045281 Mon Sep 17 00:00:00 2001 From: John McCall Date: Mon, 14 Feb 2011 20:37:25 +0000 Subject: [PATCH] Change the context correctly when instantiating a static data member definition. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@125517 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Sema/SemaTemplateInstantiateDecl.cpp | 6 +++--- test/CXX/class.access/p4.cpp | 10 ++++++++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/lib/Sema/SemaTemplateInstantiateDecl.cpp b/lib/Sema/SemaTemplateInstantiateDecl.cpp index 3475cc142d..14524235d5 100644 --- a/lib/Sema/SemaTemplateInstantiateDecl.cpp +++ b/lib/Sema/SemaTemplateInstantiateDecl.cpp @@ -2434,13 +2434,13 @@ void Sema::InstantiateStaticDataMemberDefinition( // Enter the scope of this instantiation. We don't use // PushDeclContext because we don't have a scope. - DeclContext *PreviousContext = CurContext; - CurContext = Var->getDeclContext(); + ContextRAII previousContext(*this, Var->getDeclContext()); VarDecl *OldVar = Var; Var = cast_or_null(SubstDecl(Def, Var->getDeclContext(), getTemplateInstantiationArgs(Var))); - CurContext = PreviousContext; + + previousContext.pop(); if (Var) { MemberSpecializationInfo *MSInfo = OldVar->getMemberSpecializationInfo(); diff --git a/test/CXX/class.access/p4.cpp b/test/CXX/class.access/p4.cpp index e4e9ff0496..a8a2ef928e 100644 --- a/test/CXX/class.access/p4.cpp +++ b/test/CXX/class.access/p4.cpp @@ -498,3 +498,13 @@ namespace rdar8876150 { return !b; } } + +namespace test23 { + template class A { + A(); + static A instance; + }; + + template A A::instance; + template class A; +} -- 2.50.1