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.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@98559 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/SemaObjCProperty.cpp b/lib/Sema/SemaObjCProperty.cpp
index 02bfbe7..7659062 100644
--- a/lib/Sema/SemaObjCProperty.cpp
+++ b/lib/Sema/SemaObjCProperty.cpp
@@ -66,6 +66,18 @@
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 @@
// 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 @@
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