diff options
author | Douglas Gregor <dgregor@apple.com> | 2012-02-24 17:41:38 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2012-02-24 17:41:38 +0000 |
commit | 3a08c1cd3bb40eaabc096697389b8507c719092b (patch) | |
tree | 874cb16a149be856ba6ab7961a8a65763398bf71 | |
parent | dd5a59baedc99d2c2058b6c3b59f7860e45cdcc5 (diff) | |
download | bcm5719-llvm-3a08c1cd3bb40eaabc096697389b8507c719092b.tar.gz bcm5719-llvm-3a08c1cd3bb40eaabc096697389b8507c719092b.zip |
Two minor, related fixes for template instantiation with blocks:
- Make sure that the block expression is instantiation-dependent if the
block is in a dependent context
- Make sure that the C++ 'this' expression gets captured even if we
don't rebuild the AST node during template instantiation. This would
also have manifested as a bug for lambdas.
Fixes <rdar://problem/10832617>.
llvm-svn: 151372
-rw-r--r-- | clang/include/clang/AST/Expr.h | 5 | ||||
-rw-r--r-- | clang/lib/Sema/TreeTransform.h | 8 | ||||
-rw-r--r-- | clang/test/CodeGenCXX/blocks.cpp | 15 |
3 files changed, 23 insertions, 5 deletions
diff --git a/clang/include/clang/AST/Expr.h b/clang/include/clang/AST/Expr.h index b9c3220c0b8..741b47e560d 100644 --- a/clang/include/clang/AST/Expr.h +++ b/clang/include/clang/AST/Expr.h @@ -4220,9 +4220,8 @@ protected: public: BlockExpr(BlockDecl *BD, QualType ty) : Expr(BlockExprClass, ty, VK_RValue, OK_Ordinary, - ty->isDependentType(), false, - // FIXME: Check for instantiate-dependence in the statement? - ty->isInstantiationDependentType(), + ty->isDependentType(), ty->isDependentType(), + ty->isInstantiationDependentType() || BD->isDependentContext(), false), TheBlock(BD) {} diff --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h index f0b5f4e2419..11f03fc133a 100644 --- a/clang/lib/Sema/TreeTransform.h +++ b/clang/lib/Sema/TreeTransform.h @@ -7038,9 +7038,12 @@ TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) { T = getSema().Context.getPointerType( getSema().Context.getRecordType(cast<CXXRecordDecl>(DC))); - if (!getDerived().AlwaysRebuild() && T == E->getType()) + if (!getDerived().AlwaysRebuild() && T == E->getType()) { + // Make sure that we capture 'this'. + getSema().CheckCXXThisCapture(E->getLocStart()); return SemaRef.Owned(E); - + } + return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit()); } @@ -8539,6 +8542,7 @@ TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) { oldCapture)); assert(blockScope->CaptureMap.count(newCapture)); } + assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured()); } #endif diff --git a/clang/test/CodeGenCXX/blocks.cpp b/clang/test/CodeGenCXX/blocks.cpp index 3d7fcfddbe2..eb544787da7 100644 --- a/clang/test/CodeGenCXX/blocks.cpp +++ b/clang/test/CodeGenCXX/blocks.cpp @@ -211,3 +211,18 @@ namespace test7 { return ^{ return *p; }(); } } + +namespace test8 { + // <rdar://problem/10832617>: failure to capture this after skipping rebuild + // of the 'this' pointer. + struct X { + int x; + + template<typename T> + int foo() { + return ^ { return x; }(); + } + }; + + template int X::foo<int>(); +} |