summaryrefslogtreecommitdiffstats
path: root/lib/Sema/SemaAccess.cpp
diff options
context:
space:
mode:
authorJohn McCall <rjmccall@apple.com>2013-02-22 03:52:55 +0000
committerJohn McCall <rjmccall@apple.com>2013-02-22 03:52:55 +0000
commit637619b915888ead5576d19508644e4eb9024078 (patch)
tree72c742d0b253969597160fd74af17bd3bc98dec4 /lib/Sema/SemaAccess.cpp
parent8dadf15224f1a8df96793e5fc4e0b0e38a5ffbe4 (diff)
Only suppress instance context if a member is actually
accessible in its declaring class; otherwise we might fail to apply [class.protected] when considering accessibility in derived classes. Noticed by inspection; <rdar://13270329>. I had an existing test wrong. Here's why it's wrong: Follow the rules (and notation) of [class.access]p5. The naming class (N) is B and the context (R) is D::getX. - 'x' as a member of B is protected, but R does not occur in a member or friend of a class derived from B. - There does exist a base class of B, A, which is accessible from R, and 'x' is accessible at R when named in A because 'x' as a member of A is protected and R occurs in a member of a class, D, that is derived from A; however, by [class.protected], the class of the object expression must be equal to or derived from that class, and A does not derive from D. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@175858 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaAccess.cpp')
-rw-r--r--lib/Sema/SemaAccess.cpp8
1 files changed, 6 insertions, 2 deletions
diff --git a/lib/Sema/SemaAccess.cpp b/lib/Sema/SemaAccess.cpp
index 229e6f4b8f..55bd76b737 100644
--- a/lib/Sema/SemaAccess.cpp
+++ b/lib/Sema/SemaAccess.cpp
@@ -1317,7 +1317,13 @@ static AccessResult IsAccessible(Sema &S,
FinalAccess = Target->getAccess();
switch (HasAccess(S, EC, DeclaringClass, FinalAccess, Entity)) {
case AR_accessible:
+ // Target is accessible at EC when named in its declaring class.
+ // We can now hill-climb and simply check whether the declaring
+ // class is accessible as a base of the naming class. This is
+ // equivalent to checking the access of a notional public
+ // member with no instance context.
FinalAccess = AS_public;
+ Entity.suppressInstanceContext();
break;
case AR_inaccessible: break;
case AR_dependent: return AR_dependent; // see above
@@ -1325,8 +1331,6 @@ static AccessResult IsAccessible(Sema &S,
if (DeclaringClass == NamingClass)
return (FinalAccess == AS_public ? AR_accessible : AR_inaccessible);
-
- Entity.suppressInstanceContext();
} else {
FinalAccess = AS_public;
}