summaryrefslogtreecommitdiffstats
path: root/clang/lib/Sema
diff options
context:
space:
mode:
authorJohn McCall <rjmccall@apple.com>2010-05-20 01:18:31 +0000
committerJohn McCall <rjmccall@apple.com>2010-05-20 01:18:31 +0000
commit87fe5d561815de46450813c3d50e9c338c97dc1e (patch)
treefbe116d7c0893e6fce12932c89dad90daf4880e8 /clang/lib/Sema
parent1d881510791582a045d0f178779fc486295f9eb2 (diff)
downloadbcm5719-llvm-87fe5d561815de46450813c3d50e9c338c97dc1e.tar.gz
bcm5719-llvm-87fe5d561815de46450813c3d50e9c338c97dc1e.zip
Support implicitly closing on 'this' in a block. Fixed PR7165.
(the codegen works here, too, but that's annoying to test without execution) llvm-svn: 104202
Diffstat (limited to 'clang/lib/Sema')
-rw-r--r--clang/lib/Sema/SemaExpr.cpp13
-rw-r--r--clang/lib/Sema/SemaExprCXX.cpp6
-rw-r--r--clang/lib/Sema/SemaTemplate.cpp8
3 files changed, 15 insertions, 12 deletions
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 5e1f21b4c3b..67c2fcbb9ea 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/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/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index 62b7b4abbc0..58493820506 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/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/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index 91ef67e1c9a..3242f70f128 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/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.
OpenPOWER on IntegriCloud