diff options
Diffstat (limited to 'clang')
| -rw-r--r-- | clang/lib/Sema/SemaCXXCast.cpp | 4 | ||||
| -rw-r--r-- | clang/lib/Sema/SemaType.cpp | 10 | ||||
| -rw-r--r-- | clang/test/SemaObjCXX/const-cast.mm | 13 |
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); +} |

