]> granicus.if.org Git - clang/commitdiff
Patch to check for ObjC's property type.
authorFariborz Jahanian <fjahanian@apple.com>
Tue, 16 Dec 2008 17:51:01 +0000 (17:51 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Tue, 16 Dec 2008 17:51:01 +0000 (17:51 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@61090 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/DiagnosticKinds.def
lib/Sema/SemaDeclObjC.cpp
test/SemaObjC/property-typecheck-2.m [new file with mode: 0644]

index 8b0bd277672506d2e5bb7b74ed8763f16792968e..c900a230733a9832f807c2dfd15851765ba2a5db 100644 (file)
@@ -456,6 +456,8 @@ DIAG(warn_objc_property_default_assign_on_object, WARNING,
      "default property attribute 'assign' not appropriate for non-gc object")
 DIAG(err_objc_property_requires_object, ERROR,
      "property with '%0' attribute must be of object type")
+DIAG(err_property_type, ERROR,
+     "property cannot have type %0 (array or function type)")
 DIAG(err_objc_directive_only_in_protocol, ERROR,
      "directive may only be specified in protocols only")
 DIAG(err_missing_catch_finally, ERROR,
index 417803e5c16f29489b7ad4824b5cecff895bf717..7b6059415a063f65162da2283144fb48f5567f33 100644 (file)
@@ -1437,6 +1437,10 @@ Sema::DeclTy *Sema::ActOnProperty(Scope *S, SourceLocation AtLoc,
       }
     }
 
+  Type *t = T.getTypePtr();
+  if (t->isArrayType() || t->isFunctionType())
+    Diag(AtLoc, diag::err_property_type) << T;
+  
   ObjCPropertyDecl *PDecl = ObjCPropertyDecl::Create(Context, AtLoc, 
                                                      FD.D.getIdentifier(), T);
   // Regardless of setter/getter attribute, we save the default getter/setter
diff --git a/test/SemaObjC/property-typecheck-2.m b/test/SemaObjC/property-typecheck-2.m
new file mode 100644 (file)
index 0000000..b8da661
--- /dev/null
@@ -0,0 +1,12 @@
+// RUN: clang -fsyntax-only -verify %s
+
+typedef int T[2];
+typedef void (F)(void);
+
+@interface A
+@property(assign) T p2;  // expected-error {{property cannot have type 'T' (array or function type)}}
+
+@property(assign) F f2; // expected-error {{property cannot have type 'F' (array or function type)}}
+
+@end
+