[cfe-commits] r91575 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/SemaDeclObjC.cpp test/SemaObjC/property.m

Fariborz Jahanian fjahanian at apple.com
Wed Dec 16 16:49:09 PST 2009


Author: fjahanian
Date: Wed Dec 16 18:49:09 2009
New Revision: 91575

URL: http://llvm.org/viewvc/llvm-project?rev=91575&view=rev
Log:
Diagnose duplicate declaration of a property. Fixes
PR5809

Modified:
    cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
    cfe/trunk/lib/Sema/SemaDeclObjC.cpp
    cfe/trunk/test/SemaObjC/property.m

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=91575&r1=91574&r2=91575&view=diff

==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Wed Dec 16 18:49:09 2009
@@ -1695,6 +1695,8 @@
 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<

Modified: cfe/trunk/lib/Sema/SemaDeclObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclObjC.cpp?rev=91575&r1=91574&r2=91575&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclObjC.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclObjC.cpp Wed Dec 16 18:49:09 2009
@@ -2032,7 +2032,14 @@
   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;

Modified: cfe/trunk/test/SemaObjC/property.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/property.m?rev=91575&r1=91574&r2=91575&view=diff

==============================================================================
--- cfe/trunk/test/SemaObjC/property.m (original)
+++ cfe/trunk/test/SemaObjC/property.m Wed Dec 16 18:49:09 2009
@@ -53,3 +53,12 @@
 @property(copy) BYObjectIdentifier identifier;
 @end
 
+ at interface Foo2 
+{
+  int ivar;
+}
+ at property int treeController;  // expected-note {{property declared here}}
+ at property int ivar;	// OK
+ at property int treeController;  // expected-error {{property has a previous declaration}}
+ at end
+





More information about the cfe-commits mailing list