From: Fariborz Jahanian Date: Wed, 6 Jan 2010 21:38:30 +0000 (+0000) Subject: Fix a bug when property is redeclared in multiple X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b73e281956ff1ba40c921511a2cd6e7e76ed86a7;p=clang Fix a bug when property is redeclared in multiple continuation classes and its original declaration is imported from a protocol. This fixes radar 7509234. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@92856 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaDeclObjC.cpp b/lib/Sema/SemaDeclObjC.cpp index 115a433303..f627c23d76 100644 --- a/lib/Sema/SemaDeclObjC.cpp +++ b/lib/Sema/SemaDeclObjC.cpp @@ -2019,6 +2019,32 @@ Sema::DeclPtrTy Sema::ActOnProperty(Scope *S, SourceLocation AtLoc, Diag(AtLoc, diag::warn_property_attr_mismatch); Diag(PIDecl->getLocation(), diag::note_property_declare); } + DeclContext *DC = dyn_cast(CCPrimary); + assert(DC && "ClassDecl is not a DeclContext"); + DeclContext::lookup_result Found = + DC->lookup(PIDecl->getDeclName()); + bool PropertyInPrimaryClass = false; + for (; Found.first != Found.second; ++Found.first) + if (isa(*Found.first)) { + PropertyInPrimaryClass = true; + break; + } + if (!PropertyInPrimaryClass) { + // Protocol is not in the primary class. Must build one for it. + ObjCDeclSpec ProtocolPropertyODS; + // FIXME. Assuming that ObjCDeclSpec::ObjCPropertyAttributeKind and + // ObjCPropertyDecl::PropertyAttributeKind have identical values. + // Should consolidate both into one enum type. + ProtocolPropertyODS.setPropertyAttributes( + (ObjCDeclSpec::ObjCPropertyAttributeKind)PIkind); + DeclPtrTy ProtocolPtrTy = + ActOnProperty(S, AtLoc, FD, ProtocolPropertyODS, + PIDecl->getGetterName(), + PIDecl->getSetterName(), + DeclPtrTy::make(CCPrimary), isOverridingProperty, + MethodImplKind); + PIDecl = ProtocolPtrTy.getAs(); + } PIDecl->makeitReadWriteAttribute(); if (Attributes & ObjCDeclSpec::DQ_PR_retain) PIDecl->setPropertyAttributes(ObjCPropertyDecl::OBJC_PR_retain); diff --git a/test/SemaObjC/continuation-class-property.m b/test/SemaObjC/continuation-class-property.m new file mode 100644 index 0000000000..c48a23d62a --- /dev/null +++ b/test/SemaObjC/continuation-class-property.m @@ -0,0 +1,24 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s +// radar 7509234 + +@protocol Foo +@property (readonly, copy) id foos; +@end + +@interface Bar { +} + +@end + +@interface Baz { +} +@end + +@interface Bar () +@property (readwrite, copy) id foos; +@end + +@interface Baz () +@property (readwrite, copy) id foos; +@end +