]> granicus.if.org Git - clang/commitdiff
objc: allow typedef'ing an id to a pointer to a c-struct only.
authorFariborz Jahanian <fjahanian@apple.com>
Mon, 14 May 2012 22:48:56 +0000 (22:48 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Mon, 14 May 2012 22:48:56 +0000 (22:48 +0000)
// rdar://11356439

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@156788 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaDecl.cpp
test/SemaObjC/id.m

index 3e660b59869332bd7a6bc05b53a8e948991ce3b8..9e7f28b24d4274f1a2a7df34cf725a2376154cb7 100644 (file)
@@ -1518,12 +1518,22 @@ void Sema::MergeTypedefNameDecl(TypedefNameDecl *New, LookupResult &OldDecls) {
     switch (TypeID->getLength()) {
     default: break;
     case 2:
-      if (!TypeID->isStr("id"))
-        break;
-      Context.setObjCIdRedefinitionType(New->getUnderlyingType());
-      // Install the built-in type for 'id', ignoring the current definition.
-      New->setTypeForDecl(Context.getObjCIdType().getTypePtr());
-      return;
+      {
+        if (!TypeID->isStr("id"))
+          break;
+        QualType T = New->getUnderlyingType();
+        if (!T->isPointerType())
+          break;
+        if (!T->isVoidPointerType()) {
+          QualType PT = T->getAs<PointerType>()->getPointeeType();
+          if (!PT->isStructureType())
+            break;
+        }
+        Context.setObjCIdRedefinitionType(T);
+        // Install the built-in type for 'id', ignoring the current definition.
+        New->setTypeForDecl(Context.getObjCIdType().getTypePtr());
+        return;
+      }
     case 5:
       if (!TypeID->isStr("Class"))
         break;
index 27b84dedf8e664ec628995517b536e3571e7d482..ced406ebd29b83f65d088df1f5985a8fd27cd093 100644 (file)
@@ -16,6 +16,16 @@ void foo() {
 }
 
 // Test attempt to redefine 'id' in an incompatible fashion.
-typedef int id;  // FIXME: Decide how we want to deal with this (now that 'id' is more of a built-in type).
+// rdar://11356439
+typedef int id;  // expected-error {{typedef redefinition with different types ('int' vs 'id')}}
 id b;
 
+typedef double id;  // expected-error {{typedef redefinition with different types ('double' vs 'id')}}
+
+typedef char *id; // expected-error {{typedef redefinition with different types ('char *' vs 'id')}}
+
+typedef union U{ int iu; } *id; // expected-error {{typedef redefinition with different types ('union U *' vs 'id')}}
+
+void test11356439(id o) {
+  o->x; // expected-error {{member reference base type 'id' is not a structure or union}}
+}