From 105ec4bb8e969eee18b4c2f503b46b17f3e2f364 Mon Sep 17 00:00:00 2001 From: Fariborz Jahanian Date: Tue, 16 Dec 2008 17:51:01 +0000 Subject: [PATCH] Patch to check for ObjC's property type. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@61090 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Basic/DiagnosticKinds.def | 2 ++ lib/Sema/SemaDeclObjC.cpp | 4 ++++ test/SemaObjC/property-typecheck-2.m | 12 ++++++++++++ 3 files changed, 18 insertions(+) create mode 100644 test/SemaObjC/property-typecheck-2.m diff --git a/include/clang/Basic/DiagnosticKinds.def b/include/clang/Basic/DiagnosticKinds.def index 8b0bd27767..c900a23073 100644 --- a/include/clang/Basic/DiagnosticKinds.def +++ b/include/clang/Basic/DiagnosticKinds.def @@ -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, diff --git a/lib/Sema/SemaDeclObjC.cpp b/lib/Sema/SemaDeclObjC.cpp index 417803e5c1..7b6059415a 100644 --- a/lib/Sema/SemaDeclObjC.cpp +++ b/lib/Sema/SemaDeclObjC.cpp @@ -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 index 0000000000..b8da661126 --- /dev/null +++ b/test/SemaObjC/property-typecheck-2.m @@ -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 + -- 2.50.1