[cfe-commits] r98559 - in /cfe/trunk: lib/Sema/SemaObjCProperty.cpp test/SemaObjC/duplicate-property.m
Ted Kremenek
kremenek at apple.com
Mon Mar 15 11:47:25 PDT 2010
Author: kremenek
Date: Mon Mar 15 13:47:25 2010
New Revision: 98559
URL: http://llvm.org/viewvc/llvm-project?rev=98559&view=rev
Log:
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.
Added:
cfe/trunk/test/SemaObjC/duplicate-property.m
Modified:
cfe/trunk/lib/Sema/SemaObjCProperty.cpp
Modified: cfe/trunk/lib/Sema/SemaObjCProperty.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaObjCProperty.cpp?rev=98559&r1=98558&r2=98559&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaObjCProperty.cpp (original)
+++ cfe/trunk/lib/Sema/SemaObjCProperty.cpp Mon Mar 15 13:47:25 2010
@@ -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
Added: cfe/trunk/test/SemaObjC/duplicate-property.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/duplicate-property.m?rev=98559&view=auto
==============================================================================
--- cfe/trunk/test/SemaObjC/duplicate-property.m (added)
+++ cfe/trunk/test/SemaObjC/duplicate-property.m Mon Mar 15 13:47:25 2010
@@ -0,0 +1,8 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+ at interface Foo {
+ id x;
+}
+ at property (nonatomic, retain) id x;
+ at property (nonatomic, retain) id x; // expected-error{{property has a previous declaration}}
+ at end
More information about the cfe-commits
mailing list