Objective-C. Attributes on class declarations carry over
authorFariborz Jahanian <fjahanian@apple.com>
Wed, 18 Jun 2014 17:58:27 +0000 (17:58 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Wed, 18 Jun 2014 17:58:27 +0000 (17:58 +0000)
to forward class declarations for diagnosis.
// rdar://16681279

llvm-svn: 211195

clang/lib/Sema/SemaExpr.cpp
clang/test/SemaObjC/class-unavail-warning.m

index 0e1aade..4b4cb6c 100644 (file)
@@ -87,6 +87,12 @@ static AvailabilityResult DiagnoseAvailabilityOfDecl(Sema &S,
                               bool ObjCPropertyAccess) {
   // See if this declaration is unavailable or deprecated.
   std::string Message;
+    
+  // Forward class declarations get their attributes from their definition.
+  if (ObjCInterfaceDecl *IDecl = dyn_cast<ObjCInterfaceDecl>(D)) {
+    if (IDecl->getDefinition())
+      D = IDecl->getDefinition();
+  }
   AvailabilityResult Result = D->getAvailability(&Message);
   if (const EnumConstantDecl *ECD = dyn_cast<EnumConstantDecl>(D))
     if (Result == AR_Available) {
index a337c97..b903e27 100644 (file)
@@ -15,7 +15,7 @@ __attribute__((unavailable("not available")))
 
 @end
 
-@interface Foo {
+@interface Gorf {
   MyClass *ivar; // expected-error {{unavailable}}
 }
 - (MyClass *)meth; // expected-error {{unavailable}}
@@ -40,3 +40,30 @@ int main() {
 
  return 0;
 }
+
+// rdar://16681279
+@interface NSObject @end
+
+__attribute__((visibility("default"))) __attribute__((availability(macosx,unavailable)))
+@interface Foo : NSObject @end // expected-note 3 {{'Foo' has been explicitly marked unavailable here}}
+@interface AppDelegate  : NSObject
+@end
+
+@class Foo;
+
+@implementation AppDelegate
+- (void) applicationDidFinishLaunching
+{
+  Foo *foo = 0; // expected-error {{'Foo' is unavailable}}
+}
+@end
+
+@class Foo;
+Foo *g_foo = 0; // expected-error {{'Foo' is unavailable}}
+
+@class Foo;
+@class Foo;
+@class Foo;
+Foo * f_func() { // expected-error {{'Foo' is unavailable}}
+  return 0; 
+}