]> granicus.if.org Git - clang/commitdiff
Diagnose duplicate declaration of a property. Fixes
authorFariborz Jahanian <fjahanian@apple.com>
Thu, 17 Dec 2009 00:49:09 +0000 (00:49 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Thu, 17 Dec 2009 00:49:09 +0000 (00:49 +0000)
PR5809

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@91575 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/DiagnosticSemaKinds.td
lib/Sema/SemaDeclObjC.cpp
test/SemaObjC/property.m

index 2c3f85f2be3606554a59168a02ca17556a12a029..beb44f275a72e29c6d9bc76b2102b0929547b6d3 100644 (file)
@@ -1695,6 +1695,8 @@ def err_unexpected_interface : Error<
 def err_ref_non_value : Error<"%0 does not refer to a value">;
 def err_property_not_found : Error<
   "property %0 not found on object of type %1">;
+def err_duplicate_property : Error<
+  "property has a previous declaration">;
 def ext_gnu_void_ptr : Extension<
   "use of GNU void* extension">, InGroup<PointerArith>;
 def ext_gnu_ptr_func_arith : Extension<
index ea7d9a93858317f91544dc31aae90408913fca26..beadb588f3e939270294a39a08745cf34e9ecc53 100644 (file)
@@ -2032,7 +2032,14 @@ Sema::DeclPtrTy Sema::ActOnProperty(Scope *S, SourceLocation AtLoc,
   ObjCPropertyDecl *PDecl = ObjCPropertyDecl::Create(Context, DC,
                                                      FD.D.getIdentifierLoc(),
                                                      FD.D.getIdentifier(), T);
-  DC->addDecl(PDecl);
+  DeclContext::lookup_result Found = DC->lookup(PDecl->getDeclName());
+  if (Found.first != Found.second && isa<ObjCPropertyDecl>(*Found.first)) {
+    Diag(PDecl->getLocation(), diag::err_duplicate_property);
+    Diag((*Found.first)->getLocation(), diag::note_property_declare);
+    PDecl->setInvalidDecl();
+  }
+  else
+    DC->addDecl(PDecl);
 
   if (T->isArrayType() || T->isFunctionType()) {
     Diag(AtLoc, diag::err_property_type) << T;
index a7f3c2012f7ac8d2f69a1a4eb7932d36ce894dce..bc2056c9791186103136fbcbd0b4d0d6e39ff6e7 100644 (file)
@@ -53,3 +53,12 @@ typedef id BYObjectIdentifier;
 @property(copy) BYObjectIdentifier identifier;
 @end
 
+@interface Foo2 
+{
+  int ivar;
+}
+@property int treeController;  // expected-note {{property declared here}}
+@property int ivar;    // OK
+@property int treeController;  // expected-error {{property has a previous declaration}}
+@end
+