Improve checking of member expressions where the base type is a dependent type.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@71956 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp
index 77902d5..6a02538 100644
--- a/lib/Sema/SemaExpr.cpp
+++ b/lib/Sema/SemaExpr.cpp
@@ -2035,16 +2035,22 @@
                             diag::err_typecheck_member_reference_arrow)
         << BaseType << BaseExpr->getSourceRange());
   } else {
-    // We use isTemplateTypeParmType directly here, instead of simply checking
-    // whether BaseType is dependent, because we want to report an error for
-    //
-    // T *t;
-    // t.foo;
-    //
-    //
-    if (BaseType->isTemplateTypeParmType()) 
-      return Owned(new (Context) MemberExpr(BaseExpr, false, 0,
-                                            MemberLoc, Context.DependentTy));
+    if (BaseType->isDependentType()) {
+      // Require that the base type isn't a pointer type 
+      // (so we'll report an error for)
+      // T* t;
+      // t.f;
+      // 
+      // In Obj-C++, however, the above expression is valid, since it could be
+      // accessing the 'f' property if T is an Obj-C interface. The extra check
+      // allows this, while still reporting an error if T is a struct pointer.
+      const PointerType *PT = BaseType->getAsPointerType();
+
+      if (!PT || (getLangOptions().ObjC1 && 
+                  !PT->getPointeeType()->isRecordType()))
+        return Owned(new (Context) MemberExpr(BaseExpr, false, 0,
+                                              MemberLoc, Context.DependentTy));
+    }
   }
 
   // Handle field access to simple records.  This also handles access to fields