Diagnose implementation of a property declared in a category

in its class implementation instead of crashing. Fixes radar 7350345.

llvm-svn: 85813
This commit is contained in:
Fariborz Jahanian 2009-11-02 18:45:36 +00:00
parent a38a4dfea7
commit ec344ed2f5
3 changed files with 31 additions and 0 deletions

View File

@ -271,6 +271,11 @@ def error_missing_property_context : Error<
"missing context for property implementation declaration">;
def error_bad_property_decl : Error<
"property implementation must have its declaration in interface %0">;
def error_category_property : Error<
"property declared in category %0 cannot be implemented in "
"class implementation">;
def note_category_property : Note<
"property declared here">;
def error_synthesize_category_decl : Error<
"@synthesize not allowed in a category's implementation">;
def error_missing_property_interface : Error<

View File

@ -2047,6 +2047,14 @@ Sema::DeclPtrTy Sema::ActOnPropertyImplDecl(SourceLocation AtLoc,
Diag(PropertyLoc, diag::error_bad_property_decl) << IDecl->getDeclName();
return DeclPtrTy();
}
if (const ObjCCategoryDecl *CD =
dyn_cast<ObjCCategoryDecl>(property->getDeclContext())) {
if (CD->getIdentifier()) {
Diag(PropertyLoc, diag::error_category_property) << CD->getDeclName();
Diag(property->getLocation(), diag::note_category_property);
return DeclPtrTy();
}
}
} else if ((CatImplClass = dyn_cast<ObjCCategoryImplDecl>(ClassImpDecl))) {
if (Synthesize) {
Diag(AtLoc, diag::error_synthesize_category_decl);

View File

@ -0,0 +1,18 @@
// RUN: clang-cc -fsyntax-only -verify %s
@interface IDELogNavigator
{
id selectedObjects;
}
@end
@interface IDELogNavigator (CAT)
@property (readwrite, retain) id selectedObjects; // expected-note {{property declared here}}
@property (readwrite, retain) id d_selectedObjects; // expected-note {{property declared here}}
@end
@implementation IDELogNavigator
@synthesize selectedObjects = _selectedObjects; // expected-error {{property declared in category 'CAT' cannot be implemented in class implementation}}
@dynamic d_selectedObjects; // expected-error {{property declared in category 'CAT' cannot be implemented in class implementation}}
@end