]> granicus.if.org Git - clang/commitdiff
objc: use objc_suppress_autosynthesis attribute on classes
authorFariborz Jahanian <fjahanian@apple.com>
Tue, 3 Jan 2012 19:46:00 +0000 (19:46 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Tue, 3 Jan 2012 19:46:00 +0000 (19:46 +0000)
which should not be default synthesized.

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

lib/Sema/SemaDeclObjC.cpp
lib/Sema/SemaObjCProperty.cpp
test/SemaObjC/default-synthesize-3.m [new file with mode: 0644]

index bc35055722154dadc78a57625f1e8e3349a80220..ad230b471319a7034370f024b5dd781cfa805c61 100644 (file)
@@ -1665,9 +1665,10 @@ void Sema::ImplMethodsVsClassMethods(Scope *S, ObjCImplDecl* IMPDecl,
   // Check and see if properties declared in the interface have either 1)
   // an implementation or 2) there is a @synthesize/@dynamic implementation
   // of the property in the @implementation.
-  if (isa<ObjCInterfaceDecl>(CDecl) &&
-        !(LangOpts.ObjCDefaultSynthProperties && LangOpts.ObjCNonFragileABI2))
-    DiagnoseUnimplementedProperties(S, IMPDecl, CDecl, InsMap);
+  if (const ObjCInterfaceDecl *IDecl = dyn_cast<ObjCInterfaceDecl>(CDecl))
+    if  (!(LangOpts.ObjCDefaultSynthProperties && LangOpts.ObjCNonFragileABI2) ||
+      IDecl->isObjCSuppressAutosynthesis())
+      DiagnoseUnimplementedProperties(S, IMPDecl, CDecl, InsMap);
       
   llvm::DenseSet<Selector> ClsMap;
   for (ObjCImplementationDecl::classmeth_iterator
index c60d1b8f5e90b2ecd7ef431ae86c59cf81c10b51..a15fc7dd8d12a9cb1e86209b6d971ca34c979e60 100644 (file)
@@ -856,7 +856,8 @@ Decl *Sema::ActOnPropertyImplDecl(Scope *S,
     }
     IC->addPropertyImplementation(PIDecl);
     if (getLangOptions().ObjCDefaultSynthProperties &&
-        getLangOptions().ObjCNonFragileABI2) {
+        getLangOptions().ObjCNonFragileABI2 &&
+        !IDecl->isObjCSuppressAutosynthesis()) {
       // Diagnose if an ivar was lazily synthesdized due to a previous
       // use and if 1) property is @dynamic or 2) property is synthesized
       // but it requires an ivar of different name.
@@ -1355,7 +1356,8 @@ void Sema::DefaultSynthesizeProperties(Scope *S, Decl *D) {
   if (!IC)
     return;
   if (ObjCInterfaceDecl* IDecl = IC->getClassInterface())
-    DefaultSynthesizeProperties(S, IC, IDecl);
+    if (!IDecl->isObjCSuppressAutosynthesis())
+      DefaultSynthesizeProperties(S, IC, IDecl);
 }
 
 void Sema::DiagnoseUnimplementedProperties(Scope *S, ObjCImplDecl* IMPDecl,
diff --git a/test/SemaObjC/default-synthesize-3.m b/test/SemaObjC/default-synthesize-3.m
new file mode 100644 (file)
index 0000000..7b07cb9
--- /dev/null
@@ -0,0 +1,33 @@
+// RUN: %clang_cc1 -x objective-c -fsyntax-only -fobjc-default-synthesize-properties -verify %s
+// RUN: %clang_cc1 -x objective-c++ -fsyntax-only -fobjc-default-synthesize-properties -verify %s
+
+__attribute ((objc_suppress_autosynthesis)) 
+@interface NoAuto
+@property int NoAutoProp; // expected-note 2 {{property declared here}}
+@end
+
+@implementation NoAuto  // expected-warning {{property 'NoAutoProp' requires method 'NoAutoProp' to be defined}} \
+                        // expected-warning {{property 'NoAutoProp' requires method 'setNoAutoProp:'}}
+@end
+
+__attribute ((objc_suppress_autosynthesis))  // redundant, just for testing
+@interface Sub : NoAuto 
+@property (copy) id SubProperty; // expected-note 2 {{property declared here}}
+@end
+
+@implementation Sub // expected-warning {{property 'SubProperty' requires method 'SubProperty' to be defined}} \
+                    // expected-warning {{property 'SubProperty' requires method 'setSubProperty:' to be defined}}
+@end
+
+@interface Deep : Sub
+@property (copy) id DeepProperty;
+@property (copy) id DeepSynthProperty;
+@property (copy) id DeepMustSynthProperty; // expected-note {{property declared here}}
+@end
+
+@implementation Deep // expected-warning {{property 'DeepMustSynthProperty' requires method 'setDeepMustSynthProperty:' to be defined}}
+@dynamic DeepProperty;
+@synthesize DeepSynthProperty;
+- (id) DeepMustSynthProperty { return 0; }
+@end
+