From: Fariborz Jahanian Date: Thu, 17 Dec 2009 00:49:09 +0000 (+0000) Subject: Diagnose duplicate declaration of a property. Fixes X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=6dd30fc45af6bdee05a735d9817b6d9c72cdce35;p=clang Diagnose duplicate declaration of a property. Fixes PR5809 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@91575 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td index 2c3f85f2be..beb44f275a 100644 --- a/include/clang/Basic/DiagnosticSemaKinds.td +++ b/include/clang/Basic/DiagnosticSemaKinds.td @@ -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; def ext_gnu_ptr_func_arith : Extension< diff --git a/lib/Sema/SemaDeclObjC.cpp b/lib/Sema/SemaDeclObjC.cpp index ea7d9a9385..beadb588f3 100644 --- a/lib/Sema/SemaDeclObjC.cpp +++ b/lib/Sema/SemaDeclObjC.cpp @@ -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(*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; diff --git a/test/SemaObjC/property.m b/test/SemaObjC/property.m index a7f3c2012f..bc2056c979 100644 --- a/test/SemaObjC/property.m +++ b/test/SemaObjC/property.m @@ -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 +