diff options
author | John McCall <rjmccall@apple.com> | 2010-05-20 01:18:31 +0000 |
---|---|---|
committer | John McCall <rjmccall@apple.com> | 2010-05-20 01:18:31 +0000 |
commit | ea1471e0e967548c596a71469702f8846dbaf3c0 (patch) | |
tree | dfb334fbc70dafb3f1a5b95ee175020a7c80b306 /lib/Sema | |
parent | 304d0faa6cac3111074cc400c1c573a6e611872b (diff) |
Support implicitly closing on 'this' in a block. Fixed PR7165.
(the codegen works here, too, but that's annoying to test without execution)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@104202 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema')
-rw-r--r-- | lib/Sema/SemaExpr.cpp | 13 | ||||
-rw-r--r-- | lib/Sema/SemaExprCXX.cpp | 6 | ||||
-rw-r--r-- | lib/Sema/SemaTemplate.cpp | 8 |
3 files changed, 15 insertions, 12 deletions
diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp index 5e1f21b4c3..67c2fcbb9e 100644 --- a/lib/Sema/SemaExpr.cpp +++ b/lib/Sema/SemaExpr.cpp @@ -602,7 +602,8 @@ Sema::BuildAnonymousStructUnionMemberReference(SourceLocation Loc, // We've found a member of an anonymous struct/union that is // inside a non-anonymous struct/union, so in a well-formed // program our base object expression is "this". - if (CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(CurContext)) { + DeclContext *DC = getFunctionLevelDeclContext(); + if (CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC)) { if (!MD->isStatic()) { QualType AnonFieldType = Context.getTagDeclType( @@ -838,9 +839,10 @@ static IMAKind ClassifyImplicitMemberAccess(Sema &SemaRef, const LookupResult &R) { assert(!R.empty() && (*R.begin())->isCXXClassMember()); + DeclContext *DC = SemaRef.getFunctionLevelDeclContext(); bool isStaticContext = - (!isa<CXXMethodDecl>(SemaRef.CurContext) || - cast<CXXMethodDecl>(SemaRef.CurContext)->isStatic()); + (!isa<CXXMethodDecl>(DC) || + cast<CXXMethodDecl>(DC)->isStatic()); if (R.isUnresolvableResult()) return isStaticContext ? IMA_Unresolved_StaticContext : IMA_Unresolved; @@ -880,7 +882,7 @@ static IMAKind ClassifyImplicitMemberAccess(Sema &SemaRef, // declaring classes, it can't be an implicit member reference (in // which case it's an error if any of those members are selected). if (IsProvablyNotDerivedFrom(SemaRef, - cast<CXXMethodDecl>(SemaRef.CurContext)->getParent(), + cast<CXXMethodDecl>(DC)->getParent(), Classes)) return (hasNonInstance ? IMA_Mixed_Unrelated : IMA_Error_Unrelated); @@ -1569,7 +1571,8 @@ Sema::BuildImplicitMemberExpr(const CXXScopeSpec &SS, // If this is known to be an instance access, go ahead and build a // 'this' expression now. - QualType ThisType = cast<CXXMethodDecl>(CurContext)->getThisType(Context); + DeclContext *DC = getFunctionLevelDeclContext(); + QualType ThisType = cast<CXXMethodDecl>(DC)->getThisType(Context); Expr *This = 0; // null signifies implicit access if (IsKnownInstance) { SourceLocation Loc = R.getNameLoc(); diff --git a/lib/Sema/SemaExprCXX.cpp b/lib/Sema/SemaExprCXX.cpp index 62b7b4abbc..5849382050 100644 --- a/lib/Sema/SemaExprCXX.cpp +++ b/lib/Sema/SemaExprCXX.cpp @@ -466,10 +466,8 @@ Action::OwningExprResult Sema::ActOnCXXThis(SourceLocation ThisLoc) { /// is a non-lvalue expression whose value is the address of the object for /// which the function is called. - if (!isa<FunctionDecl>(CurContext)) - return ExprError(Diag(ThisLoc, diag::err_invalid_this_use)); - - if (CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(CurContext)) + DeclContext *DC = getFunctionLevelDeclContext(); + if (CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC)) if (MD->isInstance()) return Owned(new (Context) CXXThisExpr(ThisLoc, MD->getThisType(Context), diff --git a/lib/Sema/SemaTemplate.cpp b/lib/Sema/SemaTemplate.cpp index 91ef67e1c9..3242f70f12 100644 --- a/lib/Sema/SemaTemplate.cpp +++ b/lib/Sema/SemaTemplate.cpp @@ -330,11 +330,13 @@ Sema::ActOnDependentIdExpression(const CXXScopeSpec &SS, const TemplateArgumentListInfo *TemplateArgs) { NestedNameSpecifier *Qualifier = static_cast<NestedNameSpecifier*>(SS.getScopeRep()); + + DeclContext *DC = getFunctionLevelDeclContext(); if (!isAddressOfOperand && - isa<CXXMethodDecl>(CurContext) && - cast<CXXMethodDecl>(CurContext)->isInstance()) { - QualType ThisType = cast<CXXMethodDecl>(CurContext)->getThisType(Context); + isa<CXXMethodDecl>(DC) && + cast<CXXMethodDecl>(DC)->isInstance()) { + QualType ThisType = cast<CXXMethodDecl>(DC)->getThisType(Context); // Since the 'this' expression is synthesized, we don't need to // perform the double-lookup check. |