r211195 - Objective-C. Attributes on class declarations carry over

Fariborz Jahanian fjahanian at apple.com
Wed Jun 18 10:58:28 PDT 2014


Author: fjahanian
Date: Wed Jun 18 12:58:27 2014
New Revision: 211195

URL: http://llvm.org/viewvc/llvm-project?rev=211195&view=rev
Log:
Objective-C. Attributes on class declarations carry over
to forward class declarations for diagnosis. 
// rdar://16681279

Modified:
    cfe/trunk/lib/Sema/SemaExpr.cpp
    cfe/trunk/test/SemaObjC/class-unavail-warning.m

Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=211195&r1=211194&r2=211195&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Wed Jun 18 12:58:27 2014
@@ -87,6 +87,12 @@ static AvailabilityResult DiagnoseAvaila
                               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) {

Modified: cfe/trunk/test/SemaObjC/class-unavail-warning.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/class-unavail-warning.m?rev=211195&r1=211194&r2=211195&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/class-unavail-warning.m (original)
+++ cfe/trunk/test/SemaObjC/class-unavail-warning.m Wed Jun 18 12:58:27 2014
@@ -15,7 +15,7 @@ __attribute__((unavailable("not availabl
 
 @end
 
- at interface Foo {
+ at interface Gorf {
   MyClass *ivar; // expected-error {{unavailable}}
 }
 - (MyClass *)meth; // expected-error {{unavailable}}
@@ -40,3 +40,30 @@ int main() {
 
  return 0;
 }
+
+// rdar://16681279
+ at interface NSObject @end
+
+__attribute__((visibility("default"))) __attribute__((availability(macosx,unavailable)))
+ at interface Foo : NSObject @end // expected-note 3 {{'Foo' has been explicitly marked unavailable here}}
+ at interface AppDelegate  : NSObject
+ at end
+
+ at class Foo;
+
+ at implementation AppDelegate
+- (void) applicationDidFinishLaunching
+{
+  Foo *foo = 0; // expected-error {{'Foo' is unavailable}}
+}
+ at end
+
+ at class Foo;
+Foo *g_foo = 0; // expected-error {{'Foo' is unavailable}}
+
+ at class Foo;
+ at class Foo;
+ at class Foo;
+Foo * f_func() { // expected-error {{'Foo' is unavailable}}
+  return 0; 
+}





More information about the cfe-commits mailing list