Diagnose that ivars in current and super class may not
be duplicates and a test case.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@61068 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp
index 5e0edcd..0d48c62 100644
--- a/lib/Sema/SemaDecl.cpp
+++ b/lib/Sema/SemaDecl.cpp
@@ -3091,6 +3091,25 @@
     if (ObjCInterfaceDecl *ID = dyn_cast<ObjCInterfaceDecl>(EnclosingDecl)) {
       ID->addInstanceVariablesToClass(ClsFields, RecFields.size(), RBrac);
       ID->addRecordToClass(Context);
+      // 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;
+              }
+          }
+      }
     }
     else if (ObjCImplementationDecl *IMPDecl = 
                dyn_cast<ObjCImplementationDecl>(EnclosingDecl)) {