Objective-C: check that when a category method is being implemented,

method type in cateogry matches the implementation.
// rdar://12519216

llvm-svn: 166518
This commit is contained in:
Fariborz Jahanian 2012-10-23 23:06:22 +00:00
parent 8e95113597
commit 6f5309cf50
2 changed files with 35 additions and 8 deletions

View File

@ -1709,6 +1709,18 @@ void Sema::MatchAllMethodDeclarations(const SelectorSet &InsMap,
}
if (ObjCInterfaceDecl *I = dyn_cast<ObjCInterfaceDecl> (CDecl)) {
// when checking that methods in implementation match their declaration,
// i.e. when WarnCategoryMethodImpl is false, check declarations in class
// extension; as well as those in categories.
if (!WarnCategoryMethodImpl)
for (const ObjCCategoryDecl *CDeclChain = I->getCategoryList();
CDeclChain; CDeclChain = CDeclChain->getNextClassCategory())
MatchAllMethodDeclarations(InsMap, ClsMap, InsMapSeen, ClsMapSeen,
IMPDecl,
const_cast<ObjCCategoryDecl *>(CDeclChain),
IncompleteImpl, false,
WarnCategoryMethodImpl);
else
// Also methods in class extensions need be looked at next.
for (const ObjCCategoryDecl *ClsExtDecl = I->getFirstClassExtension();
ClsExtDecl; ClsExtDecl = ClsExtDecl->getNextClassExtension())

View File

@ -34,3 +34,18 @@
(float) x { return 0; } // expected-warning {{conflicting parameter types in implementation of 'setCat:': 'int' vs 'float'}}
+ (int) cCat: (int) x { return 0; } // expected-warning {{conflicting return type in implementation of 'cCat:': 'void' vs 'int'}}
@end
// rdar://12519216
// test that when implementation implements method in a category, types match.
@interface testObject {}
@end
@interface testObject(Category)
- (float)returnCGFloat; // expected-note {{previous definition is here}}
@end
@implementation testObject
- (double)returnCGFloat { // expected-warning {{conflicting return type in implementation of 'returnCGFloat': 'float' vs 'double'}}
return 0.0;
}
@end