From 375d37c1298def125934bbbebca535c3867a89db Mon Sep 17 00:00:00 2001 From: Fariborz Jahanian Date: Wed, 17 Dec 2008 22:21:44 +0000 Subject: [PATCH] Patch to re-implement duplicate ivar checking (which will pass duplicate-ivar-check.m test again). git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@61161 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Sema/SemaDecl.cpp | 27 ++++++++++----------------- 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index 5ae266ef00..511103fa75 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -3029,27 +3029,20 @@ void Sema::ActOnFields(Scope* S, ObjCIvarDecl **ClsFields = reinterpret_cast(&RecFields[0]); if (ObjCInterfaceDecl *ID = dyn_cast(EnclosingDecl)) { ID->addInstanceVariablesToClass(ClsFields, RecFields.size(), RBrac); -#if 0 // Must enforce the rule that ivars in the base classes may not be // duplicates. - FieldIDs.clear(); - RecordDecl *RD = ID->getRecordForDecl(); - for (RecordDecl::field_iterator i = RD->field_begin(), - e = RD->field_end(); i != e; ++i) { - FieldDecl *FD = *i; - if (IdentifierInfo *II = FD->getIdentifier()) - if (!FieldIDs.insert(II)) { - Diag(FD->getLocation(), diag::err_duplicate_member) << II; - FD->setInvalidDecl(); - for (RecordDecl::field_iterator j = RD->field_begin(), - e1 = RD->field_end(); j != e1; ++j) - if (II == (*j)->getIdentifier()) { - Diag((*j)->getLocation(), diag::note_previous_definition); - break; - } + if (ID->getSuperClass()) { + for (ObjCInterfaceDecl::ivar_iterator IVI = ID->ivar_begin(), + IVE = ID->ivar_end(); IVI != IVE; ++IVI) { + ObjCIvarDecl* Ivar = (*IVI); + IdentifierInfo *II = Ivar->getIdentifier(); + ObjCIvarDecl* prevIvar = ID->getSuperClass()->FindIvarDeclaration(II); + if (prevIvar) { + Diag(Ivar->getLocation(), diag::err_duplicate_member) << II; + Diag(prevIvar->getLocation(), diag::note_previous_definition); } + } } -#endif } else if (ObjCImplementationDecl *IMPDecl = dyn_cast(EnclosingDecl)) { -- 2.40.0