aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/Sema/SemaTemplateInstantiate.cpp4
-rw-r--r--lib/Sema/SemaTemplateInstantiateDecl.cpp3
-rw-r--r--lib/Sema/TreeTransform.h4
-rw-r--r--test/CodeGenCXX/instantiate-blocks.cpp26
4 files changed, 33 insertions, 4 deletions
diff --git a/lib/Sema/SemaTemplateInstantiate.cpp b/lib/Sema/SemaTemplateInstantiate.cpp
index 6db0916e44..539b4c409f 100644
--- a/lib/Sema/SemaTemplateInstantiate.cpp
+++ b/lib/Sema/SemaTemplateInstantiate.cpp
@@ -1067,6 +1067,10 @@ ParmVarDecl *Sema::SubstParmVarDecl(ParmVarDecl *OldParm,
NewParm->setHasInheritedDefaultArg(OldParm->hasInheritedDefaultArg());
CurrentInstantiationScope->InstantiatedLocal(OldParm, NewParm);
+ // Set DeclContext if inside a Block.
+ if (BlockScopeInfo *CurBlock = getCurBlock())
+ NewParm->setDeclContext(CurBlock->TheDecl);
+
return NewParm;
}
diff --git a/lib/Sema/SemaTemplateInstantiateDecl.cpp b/lib/Sema/SemaTemplateInstantiateDecl.cpp
index 2fd3528532..b80e824bfd 100644
--- a/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ b/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -400,6 +400,9 @@ Decl *TemplateDeclInstantiator::VisitVarDecl(VarDecl *D) {
SemaRef.CurrentInstantiationScope->InstantiatedLocal(D, Var);
}
InstantiateAttrs(D, Var);
+ // Set DeclContext if inside a Block.
+ if (BlockScopeInfo *CurBlock = SemaRef.getCurBlock())
+ D->setDeclContext(CurBlock->TheDecl);
// Link instantiations of static data members back to the template from
// which they were instantiated.
diff --git a/lib/Sema/TreeTransform.h b/lib/Sema/TreeTransform.h
index 132d04927b..17103c515f 100644
--- a/lib/Sema/TreeTransform.h
+++ b/lib/Sema/TreeTransform.h
@@ -4198,10 +4198,6 @@ TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
if (!ND)
return SemaRef.ExprError();
- // Set DeclContext if inside a Block.
- if (BlockScopeInfo *CurBlock = SemaRef.getCurBlock())
- ND->setDeclContext(CurBlock->TheDecl);
-
if (!getDerived().AlwaysRebuild() &&
Qualifier == E->getQualifier() &&
ND == E->getDecl() &&
diff --git a/test/CodeGenCXX/instantiate-blocks.cpp b/test/CodeGenCXX/instantiate-blocks.cpp
index c8f897de82..e206582191 100644
--- a/test/CodeGenCXX/instantiate-blocks.cpp
+++ b/test/CodeGenCXX/instantiate-blocks.cpp
@@ -31,3 +31,29 @@ void test2(void)
{
foo(100, 'a');
}
+
+namespace rdar6182276 {
+extern "C" {
+int printf(const char *, ...);
+}
+
+template <typename T> T foo(T t)
+{
+ void (^testing)(int) = ^(int bar) { printf("bar is %d\n", bar); };
+ printf("bar is\n");
+ return 1;
+}
+
+template <typename T> void gorf(T t)
+{
+ foo(t);
+}
+
+
+void test(void)
+{
+ gorf(2);
+}
+}
+
+