// C++ 5.2.11p5: For a const_cast involving pointers to data members [...]
// the rules for const_cast are the same as those used for pointers.
- if (!DestType->isPointerType() && !DestType->isMemberPointerType()) {
+ if (!DestType->isPointerType() &&
+ !DestType->isMemberPointerType() &&
+ !DestType->isObjCObjectPointerType()) {
// Cannot cast to non-pointer, non-reference type. Note that, if DestType
// was a reference type, we converted it to a pointer above.
// The status of rvalue references isn't entirely clear, but it looks like
T2 = T2MPType->getPointeeType();
return true;
}
+
+ if (getLangOptions().ObjC1) {
+ const ObjCObjectPointerType *T1OPType = T1->getAs<ObjCObjectPointerType>(),
+ *T2OPType = T2->getAs<ObjCObjectPointerType>();
+ if (T1OPType && T2OPType) {
+ T1 = T1OPType->getPointeeType();
+ T2 = T2OPType->getPointeeType();
+ return true;
+ }
+ }
return false;
}
--- /dev/null
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+@class Foo;
+
+void test() {
+ const Foo *foo1 = 0;
+ Foo *foo2 = foo1; // expected-error {{cannot initialize}}
+}
+
+void test1() {
+ const Foo *foo1 = 0;
+ Foo *foo2 = const_cast<Foo*>(foo1);
+}