]> granicus.if.org Git - clang/commitdiff
Patch to diagnose a variety of misuse of property
authorFariborz Jahanian <fjahanian@apple.com>
Sat, 6 Dec 2008 01:12:43 +0000 (01:12 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Sat, 6 Dec 2008 01:12:43 +0000 (01:12 +0000)
attributes. Example would be, readonly, assign or
assign, copy, etc.

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

lib/Sema/SemaDeclObjC.cpp
test/Analysis/PR2978.m
test/Coverage/objc-language-features.inc
test/SemaObjC/continuation-class-err.m
test/SemaObjC/property-12.m [new file with mode: 0644]
test/SemaObjC/property-3.m

index 03c803054ca405212b129860bd9cf1f04f73964e..19769b82e350186bfad10244914d135556c6ae4f 100644 (file)
@@ -1229,12 +1229,22 @@ void Sema::CheckObjCPropertyAttributes(QualType PropertyTy,
                                        unsigned &Attributes) {
   // FIXME: Improve the reported location.
 
-  // readonly and readwrite conflict.
+  // readonly and readwrite/assign/retain/copy conflict.
   if ((Attributes & ObjCDeclSpec::DQ_PR_readonly) &&
-      (Attributes & ObjCDeclSpec::DQ_PR_readwrite)) {
+      (Attributes & (ObjCDeclSpec::DQ_PR_readwrite |
+                     ObjCDeclSpec::DQ_PR_assign |
+                     ObjCDeclSpec::DQ_PR_copy |
+                     ObjCDeclSpec::DQ_PR_retain))) {
+    const char * which = (Attributes & ObjCDeclSpec::DQ_PR_readwrite) ?
+                          "readwrite" :
+                         (Attributes & ObjCDeclSpec::DQ_PR_assign) ?
+                          "assign" :
+                         (Attributes & ObjCDeclSpec::DQ_PR_copy) ?
+                          "copy" : "retain";
+                         
     Diag(Loc, diag::err_objc_property_attr_mutually_exclusive)
-      << "readonly" << "readwrite";
-    Attributes &= ~ObjCDeclSpec::DQ_PR_readonly;
+      << "readonly" << which;
+    return;
   }
 
   // Check for copy or retain on non-object types.
index aa5d173807b2d6f2767bcf10eaa6aae8cb6ec9fe..0b9ae233786412ef92eb7fabff0a79169d23c4c5 100644 (file)
@@ -23,7 +23,7 @@
 @property(retain) id Y;
 @property(assign) id Z;
 @property(assign) id K;
-@property(assign, readonly) id N;
+@property(readonly) id N;
 @property(retain) id M;
 @property(retain) id V;
 @property(retain) id W;
index 793d0e5a44217ad6e9c9fa7845add24e0085c820..25988f5e53a7161cd440c91f5a572a030ce860dc 100644 (file)
@@ -16,7 +16,7 @@
   B *iv1;
 }
 
-@property(assign,readonly) int p0;
+@property(readonly) int p0;
 @property(assign,nonatomic,readwrite) int p1;
 @property(copy) id p2;
 @property(retain) id p3;
index 321615ece31c3947332bd40384eae2e3938aca0b..1ddbd6236522505a2cf5f470d73b22282ec3e01d 100644 (file)
@@ -5,7 +5,7 @@
   id _object;
   id _object1;
 }
-@property(readonly, assign) id object;
+@property(readonly) id object;
 @property(readwrite, assign) id object1;
 @end
 
diff --git a/test/SemaObjC/property-12.m b/test/SemaObjC/property-12.m
new file mode 100644 (file)
index 0000000..bdd026d
--- /dev/null
@@ -0,0 +1,32 @@
+// RUN: clang -fsyntax-only -verify %s
+
+@protocol P0
+@property(readonly,assign) id X; // expected-error {{property attributes 'readonly' and 'assign' are mutually exclusive}}
+@end
+
+@protocol P1
+@property(readonly,retain) id X; // expected-error {{property attributes 'readonly' and 'retain' are mutually exclusive}}
+@end
+
+@protocol P2
+@property(readonly,copy) id X; // expected-error {{property attributes 'readonly' and 'copy' are mutually exclusive}}
+@end
+
+@protocol P3
+@property(readonly,readwrite) id X; // expected-error {{property attributes 'readonly' and 'readwrite' are mutually exclusive}}
+@end
+
+@protocol P4
+@property(assign,copy) id X; // expected-error {{property attributes 'assign' and 'copy' are mutually exclusive}}
+@end
+
+@protocol P5
+@property(assign,retain) id X; // expected-error {{property attributes 'assign' and 'retain' are mutually exclusive}}
+@end
+
+@protocol P6
+@property(copy,retain) id X; // expected-error {{property attributes 'copy' and 'retain' are mutually exclusive}}
+@end
+
+
+
index ed1d1bd244360b69b0b19618b45a36cba1cef9c7..ead61508d5a07207a46aacc9e1e2ad790da2b575 100644 (file)
@@ -9,6 +9,6 @@
 @end
 
 @interface NOW : I
-@property (readonly, retain) id d1; // expected-warning {{attribute 'readonly' of property 'd1' restricts attribute 'readwrite' of property inherited from 'I'}} expected-warning {{property 'd1' 'copy' attribute does not match the property inherited from 'I'}}
+@property (readonly) id d1; // expected-warning {{attribute 'readonly' of property 'd1' restricts attribute 'readwrite' of property inherited from 'I'}} expected-warning {{property 'd1' 'copy' attribute does not match the property inherited from 'I'}}
 @property (readwrite, copy) I* d2; // expected-warning {{property type 'I *' does not match property type inherited from 'I'}}
 @end