aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFariborz Jahanian <fjahanian@apple.com>2009-12-17 00:49:09 +0000
committerFariborz Jahanian <fjahanian@apple.com>2009-12-17 00:49:09 +0000
commit6dd30fc45af6bdee05a735d9817b6d9c72cdce35 (patch)
tree4bc8bca8bbf8109c8ad6e906886d5458bade2678
parente6ec205d6d0f4aec27bf49ca1e8fbb139acc2f2b (diff)
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
-rw-r--r--include/clang/Basic/DiagnosticSemaKinds.td2
-rw-r--r--lib/Sema/SemaDeclObjC.cpp9
-rw-r--r--test/SemaObjC/property.m9
3 files changed, 19 insertions, 1 deletions
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<PointerArith>;
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<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;
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
+