[cfe-commits] r104019 - in /cfe/trunk: lib/Sema/SemaCXXCast.cpp lib/Sema/SemaType.cpp test/SemaObjCXX/const-cast.mm
John McCall
rjmccall at apple.com
Tue May 18 02:35:30 PDT 2010
Author: rjmccall
Date: Tue May 18 04:35:29 2010
New Revision: 104019
URL: http://llvm.org/viewvc/llvm-project?rev=104019&view=rev
Log:
Permit Objective C object pointers to be const_casted.
Added:
cfe/trunk/test/SemaObjCXX/const-cast.mm
Modified:
cfe/trunk/lib/Sema/SemaCXXCast.cpp
cfe/trunk/lib/Sema/SemaType.cpp
Modified: cfe/trunk/lib/Sema/SemaCXXCast.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaCXXCast.cpp?rev=104019&r1=104018&r2=104019&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaCXXCast.cpp (original)
+++ cfe/trunk/lib/Sema/SemaCXXCast.cpp Tue May 18 04:35:29 2010
@@ -983,7 +983,9 @@
// 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
Modified: cfe/trunk/lib/Sema/SemaType.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=104019&r1=104018&r2=104019&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaType.cpp (original)
+++ cfe/trunk/lib/Sema/SemaType.cpp Tue May 18 04:35:29 2010
@@ -1619,6 +1619,16 @@
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;
}
Added: cfe/trunk/test/SemaObjCXX/const-cast.mm
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjCXX/const-cast.mm?rev=104019&view=auto
==============================================================================
--- cfe/trunk/test/SemaObjCXX/const-cast.mm (added)
+++ cfe/trunk/test/SemaObjCXX/const-cast.mm Tue May 18 04:35:29 2010
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+ at 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);
+}
More information about the cfe-commits
mailing list