More block instantiation stuff. Set variable/param DeclContext

to block context when first instantiating them.

llvm-svn: 108266
This commit is contained in:
Fariborz Jahanian 2010-07-13 20:05:58 +00:00
parent 76a6b663a3
commit a6c7efec2b
4 changed files with 33 additions and 4 deletions

View 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;
}

View 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.

View 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() &&

View 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);
}
}