aboutsummaryrefslogtreecommitdiff
path: root/lib/Sema/SemaAccess.cpp
diff options
context:
space:
mode:
authorJohn McCall <rjmccall@apple.com>2010-01-27 03:50:35 +0000
committerJohn McCall <rjmccall@apple.com>2010-01-27 03:50:35 +0000
commit2f514480c448708ec382a684cf5e035d3a827ec8 (patch)
treeb36a27591f7094a23eee1b687113254a5c7e4779 /lib/Sema/SemaAccess.cpp
parent9b0fb629fd12bc772a32fa2cb693b06fe5863316 (diff)
Implement access-check delays for out-of-line member definitions
using the same framework we use for deprecation warnings. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@94659 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaAccess.cpp')
-rw-r--r--lib/Sema/SemaAccess.cpp37
1 files changed, 35 insertions, 2 deletions
diff --git a/lib/Sema/SemaAccess.cpp b/lib/Sema/SemaAccess.cpp
index 26bafa525d..f3c10392f7 100644
--- a/lib/Sema/SemaAccess.cpp
+++ b/lib/Sema/SemaAccess.cpp
@@ -172,8 +172,25 @@ bool Sema::CheckAccess(const LookupResult &R, NamedDecl *D,
if (Access == AS_public)
return false;
- // Otherwise, derive the current class context.
- DeclContext *DC = CurContext;
+ // If we're currently parsing a top-level declaration, delay
+ // diagnostics. This is the only case where parsing a declaration
+ // can actually change our effective context for the purposes of
+ // access control.
+ if (CurContext->isFileContext() && ParsingDeclDepth) {
+ DelayedDiagnostics.push_back(
+ DelayedDiagnostic::makeAccess(R.getNameLoc(), D, Access,
+ R.getNamingClass()));
+ return false;
+ }
+
+ return CheckEffectiveAccess(CurContext, R, D, Access);
+}
+
+/// Checks access from the given effective context.
+bool Sema::CheckEffectiveAccess(DeclContext *EffectiveContext,
+ const LookupResult &R,
+ NamedDecl *D, AccessSpecifier Access) {
+ DeclContext *DC = EffectiveContext;
while (isa<CXXRecordDecl>(DC) &&
cast<CXXRecordDecl>(DC)->isAnonymousStructOrUnion())
DC = DC->getParent();
@@ -233,6 +250,22 @@ bool Sema::CheckAccess(const LookupResult &R, NamedDecl *D,
return true;
}
+void Sema::HandleDelayedAccessCheck(DelayedDiagnostic &DD, Decl *Ctx) {
+ NamedDecl *D = DD.AccessData.Decl;
+
+ // Fake up a lookup result.
+ LookupResult R(*this, D->getDeclName(), DD.Loc, LookupOrdinaryName);
+ R.suppressDiagnostics();
+ R.setNamingClass(DD.AccessData.NamingClass);
+
+ // Pretend we did this from the context of the newly-parsed
+ // declaration.
+ DeclContext *EffectiveContext = Ctx->getDeclContext();
+
+ if (CheckEffectiveAccess(EffectiveContext, R, D, DD.AccessData.Access))
+ DD.Triggered = true;
+}
+
bool Sema::CheckUnresolvedLookupAccess(UnresolvedLookupExpr *E,
NamedDecl *D, AccessSpecifier Access) {
if (!getLangOptions().AccessControl || !E->getNamingClass())