[cfe-commits] r69098 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/SemaDeclObjC.cpp test/SemaObjC/property-category-1.m test/SemaObjC/property.m
Fariborz Jahanian
fjahanian at apple.com
Tue Apr 14 16:15:22 PDT 2009
Author: fjahanian
Date: Tue Apr 14 18:15:21 2009
New Revision: 69098
URL: http://llvm.org/viewvc/llvm-project?rev=69098&view=rev
Log:
Diagnose properties which have no implementations;
either unimplemented setter/getter or no
implementation directive.
Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/Sema/SemaDeclObjC.cpp
cfe/trunk/test/SemaObjC/property-category-1.m
cfe/trunk/test/SemaObjC/property.m
Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=69098&r1=69097&r2=69098&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Tue Apr 14 18:15:21 2009
@@ -1039,6 +1039,11 @@
"illegal qualifiers on @catch parameter">;
def err_illegal_super_cast : Error<
"cannot cast 'super' (it isn't an expression)">;
+def warn_setter_getter_impl_required : Warning<
+ "property %0 requires method %1 to be defined - "
+ "use @synthesize, @dynamic or provide a method implementation">;
+def note_property_impl_required : Note<
+ "implementation is here">;
// C++ casts
Modified: cfe/trunk/lib/Sema/SemaDeclObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclObjC.cpp?rev=69098&r1=69097&r2=69098&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclObjC.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclObjC.cpp Tue Apr 14 18:15:21 2009
@@ -903,6 +903,42 @@
E = IMPDecl->instmeth_end(); I != E; ++I)
InsMap.insert((*I)->getSelector());
+ // 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))
+ for (ObjCContainerDecl::prop_iterator P = CDecl->prop_begin(Context),
+ E = CDecl->prop_end(Context); P != E; ++P) {
+ ObjCPropertyDecl *Prop = (*P);
+ if (Prop->isInvalidDecl())
+ continue;
+ ObjCPropertyImplDecl *PI = 0;
+ // Is there a matching propery synthesize/dynamic?
+ for (ObjCImplDecl::propimpl_iterator I = IMPDecl->propimpl_begin(),
+ EI = IMPDecl->propimpl_end(); I != EI; ++I)
+ if ((*I)->getPropertyDecl() == Prop) {
+ PI = (*I);
+ break;
+ }
+ if (PI)
+ continue;
+ if (!InsMap.count(Prop->getGetterName())) {
+ Diag(Prop->getLocation(),
+ diag::warn_setter_getter_impl_required)
+ << Prop->getDeclName() << Prop->getGetterName();
+ Diag(IMPDecl->getLocation(),
+ diag::note_property_impl_required);
+ }
+
+ if (!Prop->isReadOnly() && !InsMap.count(Prop->getSetterName())) {
+ Diag(Prop->getLocation(),
+ diag::warn_setter_getter_impl_required)
+ << Prop->getDeclName() << Prop->getSetterName();
+ Diag(IMPDecl->getLocation(),
+ diag::note_property_impl_required);
+ }
+ }
+
for (ObjCInterfaceDecl::instmeth_iterator I = CDecl->instmeth_begin(Context),
E = CDecl->instmeth_end(Context); I != E; ++I) {
if (!(*I)->isSynthesized() && !InsMap.count((*I)->getSelector())) {
@@ -1798,17 +1834,15 @@
ObjCInterfaceDecl *ClassDeclared;
Ivar = IDecl->lookupInstanceVariable(Context, PropertyIvar, ClassDeclared);
if (!Ivar) {
- if (getLangOptions().ObjCNonFragileABI) {
- Ivar = ObjCIvarDecl::Create(Context, CurContext, PropertyLoc,
- PropertyIvar, PropType,
- ObjCIvarDecl::Public,
- (Expr *)0);
- property->setPropertyIvarDecl(Ivar);
- }
- else {
+ Ivar = ObjCIvarDecl::Create(Context, CurContext, PropertyLoc,
+ PropertyIvar, PropType,
+ ObjCIvarDecl::Public,
+ (Expr *)0);
+ property->setPropertyIvarDecl(Ivar);
+ if (!getLangOptions().ObjCNonFragileABI)
Diag(PropertyLoc, diag::error_missing_property_ivar_decl) << PropertyId;
- return DeclPtrTy();
- }
+ // Note! I deliberately want it to fall thru so, we have a
+ // a property implementation and to avoid future warnings.
}
else if (getLangOptions().ObjCNonFragileABI &&
NoExplicitPropertyIvar && ClassDeclared != IDecl) {
@@ -1826,7 +1860,8 @@
if (CheckAssignmentConstraints(PropType, IvarType) != Compatible) {
Diag(PropertyLoc, diag::error_property_ivar_type)
<< property->getDeclName() << Ivar->getDeclName();
- return DeclPtrTy();
+ // Note! I deliberately want it to fall thru so, we have a
+ // a property implementation and to avoid future warnings.
}
// FIXME! Rules for properties are somewhat different that those
@@ -1838,28 +1873,26 @@
lhsType->isArithmeticType()) {
Diag(PropertyLoc, diag::error_property_ivar_type)
<< property->getDeclName() << Ivar->getDeclName();
- return DeclPtrTy();
+ // Fall thru - see previous comment
}
// __weak is explicit. So it works on Canonical type.
if (PropType.isObjCGCWeak() && !IvarType.isObjCGCWeak() &&
getLangOptions().getGCMode() != LangOptions::NonGC) {
Diag(PropertyLoc, diag::error_weak_property)
<< property->getDeclName() << Ivar->getDeclName();
- return DeclPtrTy();
+ // Fall thru - see previous comment
}
if ((Context.isObjCObjectPointerType(property->getType()) ||
PropType.isObjCGCStrong()) && IvarType.isObjCGCWeak() &&
getLangOptions().getGCMode() != LangOptions::NonGC) {
Diag(PropertyLoc, diag::error_strong_property)
<< property->getDeclName() << Ivar->getDeclName();
- return DeclPtrTy();
+ // Fall thru - see previous comment
}
}
- } else if (PropertyIvar) {
- // @dynamic
- Diag(PropertyLoc, diag::error_dynamic_property_ivar_decl);
- return DeclPtrTy();
- }
+ } else if (PropertyIvar)
+ // @dynamic
+ Diag(PropertyLoc, diag::error_dynamic_property_ivar_decl);
assert (property && "ActOnPropertyImplDecl - property declaration missing");
ObjCPropertyImplDecl *PIDecl =
ObjCPropertyImplDecl::Create(Context, CurContext, AtLoc, PropertyLoc,
Modified: cfe/trunk/test/SemaObjC/property-category-1.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/property-category-1.m?rev=69098&r1=69097&r2=69098&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/property-category-1.m (original)
+++ cfe/trunk/test/SemaObjC/property-category-1.m Tue Apr 14 18:15:21 2009
@@ -36,7 +36,7 @@
///
@interface I0
- at property(readonly) int p0;
+ at property(readonly) int p0; // expected-warning {{property 'p0' requires method 'p0' to be defined}}
@end
@interface I0 (Cat0)
@@ -45,7 +45,7 @@
@interface I0 (Cat1)
@end
- at implementation I0
+ at implementation I0 // expected-note {{implementation is here}}
- (void) foo {
self.p0 = 0; // expected-error {{assigning to property with 'readonly' attribute not allowed}}
}
Modified: cfe/trunk/test/SemaObjC/property.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/property.m?rev=69098&r1=69097&r2=69098&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/property.m (original)
+++ cfe/trunk/test/SemaObjC/property.m Tue Apr 14 18:15:21 2009
@@ -17,8 +17,8 @@
@implementation I
@synthesize d1; // expected-error {{synthesized property 'd1' must either be named the same as}}
@dynamic bad; // expected-error {{property implementation must have its declaration in interface 'I'}}
- at synthesize prop_id; // expected-error {{synthesized property 'prop_id' must either be named the same}}
- at synthesize prop_id = IVAR; // expected-error {{type of property 'prop_id' does not match type of ivar 'IVAR'}}
+ at synthesize prop_id; // expected-error {{synthesized property 'prop_id' must either be named the same}} // expected-note {{previous declaration is here}}
+ at synthesize prop_id = IVAR; // expected-error {{type of property 'prop_id' does not match type of ivar 'IVAR'}} // expected-error {{property 'prop_id' is already implemented}}
@synthesize name; // OK! property with same name as an accessible ivar of same name
@end
More information about the cfe-commits
mailing list