]> granicus.if.org Git - clang/commitdiff
Set the relevent attributes declared in class extension
authorFariborz Jahanian <fjahanian@apple.com>
Mon, 22 Mar 2010 23:25:52 +0000 (23:25 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Mon, 22 Mar 2010 23:25:52 +0000 (23:25 +0000)
and fix a missing diagnostics on assigning to a read-only
property. Fixes radar 7766184.

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

lib/Sema/SemaObjCProperty.cpp
test/SemaObjC/property-in-class-extension.m [new file with mode: 0644]

index 41ed6c630cb2f2dee64018ca3aa7a7ce39a32e94..030fdaafbc0d076d6b355c41aa632cda9acd0bd5 100644 (file)
@@ -93,6 +93,11 @@ Sema::HandlePropertyInClassExtension(Scope *S, ObjCCategoryDecl *CDecl,
   ObjCPropertyDecl *PDecl =
     ObjCPropertyDecl::Create(Context, DC, FD.D.getIdentifierLoc(),
                              PropertyId, AtLoc, T);
+  if (Attributes & ObjCDeclSpec::DQ_PR_readonly)
+    PDecl->setPropertyAttributes(ObjCPropertyDecl::OBJC_PR_readonly);
+  if (Attributes & ObjCDeclSpec::DQ_PR_readwrite)
+    PDecl->setPropertyAttributes(ObjCPropertyDecl::OBJC_PR_readwrite);
+
   DC->addDecl(PDecl);
 
   // We need to look in the @interface to see if the @property was
diff --git a/test/SemaObjC/property-in-class-extension.m b/test/SemaObjC/property-in-class-extension.m
new file mode 100644 (file)
index 0000000..3f252d0
--- /dev/null
@@ -0,0 +1,15 @@
+// RUN: %clang_cc1  -fsyntax-only -verify %s
+// rdar: // 7766184
+
+@interface Foo @end
+
+@interface Foo ()
+  @property (readonly) int bar;
+@end
+
+void FUNC () {
+    Foo *foo;
+    foo.bar = 0; // expected-error {{assigning to property with 'readonly' attribute not allowed}}
+}
+
+