]> granicus.if.org Git - clang/commitdiff
More block instantiation stuff. Set variable/param DeclContext
authorFariborz Jahanian <fjahanian@apple.com>
Tue, 13 Jul 2010 20:05:58 +0000 (20:05 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Tue, 13 Jul 2010 20:05:58 +0000 (20:05 +0000)
to block context when first instantiating them.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@108266 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaTemplateInstantiate.cpp
lib/Sema/SemaTemplateInstantiateDecl.cpp
lib/Sema/TreeTransform.h
test/CodeGenCXX/instantiate-blocks.cpp

index 6db0916e44598123755763344d912597fd601d0d..539b4c409fdbc20d19437666015f512ff1e09d82 100644 (file)
@@ -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;  
 }
 
index 2fd35285324e635eb57cfc95f73448884cf146a1..b80e824bfd67f8e6643b6c06b2b47aaa1c762d1c 100644 (file)
@@ -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.
index 132d04927b94ed8e6bb18463d4252534b366cb5c..17103c515f8b3839cea8f00eb10779fdbf950c50 100644 (file)
@@ -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() &&
index c8f897de8200277580f7c975f15ca34fde0b6143..e206582191ca6514958674ef5e476efede43b3ab 100644 (file)
@@ -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);
+}
+}
+
+