diff options
| author | Ted Kremenek <kremenek@apple.com> | 2010-03-15 18:47:25 +0000 | 
|---|---|---|
| committer | Ted Kremenek <kremenek@apple.com> | 2010-03-15 18:47:25 +0000 | 
| commit | 679708ee34669b1ca045a550e6389517e6e3b15e (patch) | |
| tree | e38abc2822d96fe9055dcc5cc0860f60cd45f1fd | |
| parent | 49ee281213ee148db2a7ccdb708c8bb7d46129c0 (diff) | |
| download | bcm5719-llvm-679708ee34669b1ca045a550e6389517e6e3b15e.tar.gz bcm5719-llvm-679708ee34669b1ca045a550e6389517e6e3b15e.zip  | |
Correctly determine if the @property has been previously declared.  If
a property has the same name as the ivar it wraps then the old logic
wouldn't find the previous property declaration.
llvm-svn: 98559
| -rw-r--r-- | clang/lib/Sema/SemaObjCProperty.cpp | 24 | ||||
| -rw-r--r-- | clang/test/SemaObjC/duplicate-property.m | 8 | 
2 files changed, 25 insertions, 7 deletions
diff --git a/clang/lib/Sema/SemaObjCProperty.cpp b/clang/lib/Sema/SemaObjCProperty.cpp index 02bfbe7e395..76590629057 100644 --- a/clang/lib/Sema/SemaObjCProperty.cpp +++ b/clang/lib/Sema/SemaObjCProperty.cpp @@ -66,6 +66,18 @@ Sema::DeclPtrTy Sema::ActOnProperty(Scope *S, SourceLocation AtLoc,                                              Attributes, T, MethodImplKind));  } +static ObjCPropertyDecl *findPropertyDecl(DeclContext *DC, +                                          IdentifierInfo *propertyID) { + +  DeclContext::lookup_iterator I, E; +  llvm::tie(I, E) = DC->lookup(propertyID); +  for ( ; I != E; ++I) +    if (ObjCPropertyDecl *PD = dyn_cast<ObjCPropertyDecl>(*I)) +        return PD; + +  return 0; +} +  Sema::DeclPtrTy  Sema::HandlePropertyInClassExtension(Scope *S, ObjCCategoryDecl *CDecl,                                       SourceLocation AtLoc, FieldDeclarator &FD, @@ -79,12 +91,11 @@ Sema::HandlePropertyInClassExtension(Scope *S, ObjCCategoryDecl *CDecl,    // Diagnose if this property is already in continuation class.    DeclContext *DC = cast<DeclContext>(CDecl); -    IdentifierInfo *PropertyId = FD.D.getIdentifier(); -  DeclContext::lookup_result Found = DC->lookup(PropertyId); -  if (Found.first != Found.second && isa<ObjCPropertyDecl>(*Found.first)) { + +  if (ObjCPropertyDecl *prevDecl = findPropertyDecl(DC, PropertyId)) {      Diag(AtLoc, diag::err_duplicate_property); -    Diag((*Found.first)->getLocation(), diag::note_property_declare); +    Diag(prevDecl->getLocation(), diag::note_property_declare);      return DeclPtrTy();    } @@ -220,10 +231,9 @@ ObjCPropertyDecl *Sema::CreatePropertyDecl(Scope *S,                                                       FD.D.getIdentifierLoc(),                                                       PropertyId, AtLoc, T); -  DeclContext::lookup_result Found = DC->lookup(PropertyId); -  if (Found.first != Found.second && isa<ObjCPropertyDecl>(*Found.first)) { +  if (ObjCPropertyDecl *prevDecl = findPropertyDecl(DC, PropertyId)) {      Diag(PDecl->getLocation(), diag::err_duplicate_property); -    Diag((*Found.first)->getLocation(), diag::note_property_declare); +    Diag(prevDecl->getLocation(), diag::note_property_declare);      PDecl->setInvalidDecl();    }    else diff --git a/clang/test/SemaObjC/duplicate-property.m b/clang/test/SemaObjC/duplicate-property.m new file mode 100644 index 00000000000..fd9b68787c4 --- /dev/null +++ b/clang/test/SemaObjC/duplicate-property.m @@ -0,0 +1,8 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s + +@interface Foo { +  id x; +} +@property (nonatomic, retain) id x; +@property (nonatomic, retain) id x; // expected-error{{property has a previous declaration}} +@end  | 

