]> granicus.if.org Git - clang/commitdiff
Fix <rdar://problem/6697053> instance variable is protected.
authorSteve Naroff <snaroff@apple.com>
Thu, 26 Mar 2009 16:01:08 +0000 (16:01 +0000)
committerSteve Naroff <snaroff@apple.com>
Thu, 26 Mar 2009 16:01:08 +0000 (16:01 +0000)
Treat @package the same as @public. The documentation for @package says it is analogous to private_extern for variables/functions. Fully implementing this requires some kind of linker support (so access is denied to code outside the classes executable image). I don't believe GCC fully implements this semantic. Will discuss with Fariborz offline.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@67755 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaExpr.cpp
test/SemaObjC/ivar-access-package.m [new file with mode: 0644]

index d2972caff7d8ce6d0db93765d7c0bc1061cebb7d..c46bde00ffcaa5eafea8741e647eed3eee0d6651 100644 (file)
@@ -1876,7 +1876,8 @@ Sema::ActOnMemberReferenceExpr(Scope *S, ExprArg Base, SourceLocation OpLoc,
       // Check whether we can reference this field.
       if (DiagnoseUseOfDecl(IV, MemberLoc))
         return ExprError();
-      if (IV->getAccessControl() != ObjCIvarDecl::Public) {
+      if (IV->getAccessControl() != ObjCIvarDecl::Public &&
+          IV->getAccessControl() != ObjCIvarDecl::Package) {
         ObjCInterfaceDecl *ClassOfMethodDecl = 0;
         if (ObjCMethodDecl *MD = getCurMethodDecl())
           ClassOfMethodDecl =  MD->getClassInterface();
diff --git a/test/SemaObjC/ivar-access-package.m b/test/SemaObjC/ivar-access-package.m
new file mode 100644 (file)
index 0000000..77a15cc
--- /dev/null
@@ -0,0 +1,45 @@
+// RUN: clang-cc -fsyntax-only -verify %s
+
+typedef unsigned char BOOL;
+
+@interface NSObject {
+  id isa;
+}
++new;
++alloc;
+-init;
+-autorelease;
+@end
+
+@interface NSAutoreleasePool : NSObject
+- drain;
+@end
+@interface A : NSObject {
+@package
+    id object;
+}
+@end
+
+@interface B : NSObject
+- (BOOL)containsSelf:(A*)a;
+@end
+
+@implementation A
+@end
+
+@implementation B
+- (BOOL)containsSelf:(A*)a {
+    return a->object == self;
+}
+@end
+
+int main (int argc, const char * argv[]) {
+    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
+    A *a = [[A new] autorelease];
+    B *b = [[B new] autorelease];
+    NSLog(@"%s", [b containsSelf:a] ? "YES" : "NO");
+    [pool drain];
+    return 0;
+}
+