More detailed analysis of typecast to an objective-c pointer
in objective-c++ mode without being too lenient.

llvm-svn: 90895
diff --git a/clang/lib/Sema/SemaCXXCast.cpp b/clang/lib/Sema/SemaCXXCast.cpp
index c11b5fd..f913890 100644
--- a/clang/lib/Sema/SemaCXXCast.cpp
+++ b/clang/lib/Sema/SemaCXXCast.cpp
@@ -539,6 +539,11 @@
           return TC_Success;
         }
       }
+      else if (CStyle && DestType->isObjCObjectPointerType()) {
+        // allow c-style cast of objective-c pointers as they are pervasive.
+        Kind = CastExpr::CK_AnyPointerToObjCPointerCast;
+        return TC_Success;
+      }
     }
   }
 
@@ -1053,8 +1058,10 @@
     return TC_Failed;
   }
   
-  bool destIsPtr = DestType->isPointerType();
-  bool srcIsPtr = SrcType->isPointerType();
+  bool destIsPtr = 
+    CStyle? DestType->isAnyPointerType() : DestType->isPointerType();
+  bool srcIsPtr = 
+    CStyle ? SrcType->isAnyPointerType() : SrcType->isPointerType();
   if (!destIsPtr && !srcIsPtr) {
     // Except for std::nullptr_t->integer and lvalue->reference, which are
     // handled above, at least one of the two arguments must be a pointer.
@@ -1106,7 +1113,11 @@
     msg = diag::err_bad_cxx_cast_const_away;
     return TC_Failed;
   }
-
+  if (CStyle && DestType->isObjCObjectPointerType()) {
+    Kind = CastExpr::CK_AnyPointerToObjCPointerCast;
+    return TC_Success;
+  }
+  
   // Not casting away constness, so the only remaining check is for compatible
   // pointer categories.
   Kind = CastExpr::CK_BitCast;
@@ -1141,7 +1152,6 @@
   // Void pointers are not specified, but supported by every compiler out there.
   // So we finish by allowing everything that remains - it's got to be two
   // object pointers.
-  Kind = CastExpr::CK_BitCast;
   return TC_Success;
 }
 
@@ -1160,10 +1170,6 @@
   if (CastTy->isDependentType() || CastExpr->isTypeDependent())
     return false;
 
-  // allow c-style cast of objective-c pointers as they are pervasive.
-  if (CastTy->isObjCObjectPointerType())
-    return false;
-  
   if (!CastTy->isLValueReferenceType() && !CastTy->isRecordType())
     DefaultFunctionArrayConversion(CastExpr);