summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohn McCall <rjmccall@apple.com>2010-05-18 09:35:29 +0000
committerJohn McCall <rjmccall@apple.com>2010-05-18 09:35:29 +0000
commit0e704f7fcdf3231cf5b6ae7e758b74e47c3a9c05 (patch)
treed248aca2285668e7b114ccc4b53285ac59a60c03
parent7dfbb1faf169cf3bb407dbbf94c999e02fed3cf0 (diff)
downloadbcm5719-llvm-0e704f7fcdf3231cf5b6ae7e758b74e47c3a9c05.tar.gz
bcm5719-llvm-0e704f7fcdf3231cf5b6ae7e758b74e47c3a9c05.zip
Permit Objective C object pointers to be const_casted.
llvm-svn: 104019
-rw-r--r--clang/lib/Sema/SemaCXXCast.cpp4
-rw-r--r--clang/lib/Sema/SemaType.cpp10
-rw-r--r--clang/test/SemaObjCXX/const-cast.mm13
3 files changed, 26 insertions, 1 deletions
diff --git a/clang/lib/Sema/SemaCXXCast.cpp b/clang/lib/Sema/SemaCXXCast.cpp
index 1dbdd06eeab..c8eae2fb0a8 100644
--- a/clang/lib/Sema/SemaCXXCast.cpp
+++ b/clang/lib/Sema/SemaCXXCast.cpp
@@ -983,7 +983,9 @@ static TryCastResult TryConstCast(Sema &Self, Expr *SrcExpr, QualType DestType,
// 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
diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp
index e0216635157..59c699d498d 100644
--- a/clang/lib/Sema/SemaType.cpp
+++ b/clang/lib/Sema/SemaType.cpp
@@ -1619,6 +1619,16 @@ bool Sema::UnwrapSimilarPointerTypes(QualType& T1, QualType& T2) {
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;
}
diff --git a/clang/test/SemaObjCXX/const-cast.mm b/clang/test/SemaObjCXX/const-cast.mm
new file mode 100644
index 00000000000..933fd47de7c
--- /dev/null
+++ b/clang/test/SemaObjCXX/const-cast.mm
@@ -0,0 +1,13 @@
+// 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);
+}
OpenPOWER on IntegriCloud