diff options
author | Sebastian Redl <sebastian.redl@getdesigned.at> | 2009-01-26 22:19:12 +0000 |
---|---|---|
committer | Sebastian Redl <sebastian.redl@getdesigned.at> | 2009-01-26 22:19:12 +0000 |
commit | f20269b42843d10c930886ee661ee1dd37a4248b (patch) | |
tree | 091708b2165201afa376beeac470f69d44cb8741 | |
parent | 4adc71ae2cfc190f8d2cf58876e2a7893aa74ee0 (diff) |
Add support for member pointers to const_cast.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@63055 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/Sema/SemaNamedCast.cpp | 8 | ||||
-rw-r--r-- | test/SemaCXX/const-cast.cpp | 7 | ||||
-rw-r--r-- | www/cxx_status.html | 10 |
3 files changed, 18 insertions, 7 deletions
diff --git a/lib/Sema/SemaNamedCast.cpp b/lib/Sema/SemaNamedCast.cpp index 06fc9d83ba..2aeab44db3 100644 --- a/lib/Sema/SemaNamedCast.cpp +++ b/lib/Sema/SemaNamedCast.cpp @@ -133,7 +133,10 @@ CheckConstCast(Sema &Self, Expr *&SrcExpr, QualType DestType, SrcType = SrcExpr->getType(); } - if (!DestType->isPointerType()) { + // 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()) { // Cannot cast to non-pointer, non-reference type. Note that, if DestType // was a reference type, we converted it to a pointer above. // C++ 5.2.11p3: For two pointer types [...] @@ -141,7 +144,8 @@ CheckConstCast(Sema &Self, Expr *&SrcExpr, QualType DestType, << OrigDestType << DestRange; return; } - if (DestType->isFunctionPointerType()) { + if (DestType->isFunctionPointerType() || + DestType->isMemberFunctionPointerType()) { // Cannot cast direct function pointers. // C++ 5.2.11p2: [...] where T is any object type or the void type [...] // T is the ultimate pointee of source and target type. diff --git a/test/SemaCXX/const-cast.cpp b/test/SemaCXX/const-cast.cpp index 03a0e908eb..0c334bf9fa 100644 --- a/test/SemaCXX/const-cast.cpp +++ b/test/SemaCXX/const-cast.cpp @@ -1,5 +1,7 @@ // RUN: clang -fsyntax-only -verify %s +struct A {}; + // See if aliasing can confuse this baby. typedef char c; typedef c *cp; @@ -33,6 +35,9 @@ char ***good_const_cast_test(ccvpcvpp var) f fp = 0; // Don't misidentify fn** as a function pointer. f *fpp = const_cast<f*>(&fp); + int const A::* const A::*icapcap = 0; + int A::* A::* iapap = const_cast<int A::* A::*>(icapcap); + return var4; } @@ -52,5 +57,7 @@ short *bad_const_cast_test(char const *volatile *const volatile *var) f fp1 = 0; // Function pointers. f fp2 = const_cast<f>(fp1); // expected-error {{const_cast to 'f', which is not a reference, pointer-to-object, or pointer-to-data-member}} + void (A::*mfn)() = 0; + (void)const_cast<void (A::*)()>(mfn); // expected-error {{const_cast to 'void (struct A::*)(void)', which is not a reference, pointer-to-object, or pointer-to-data-member}} return **var3; } diff --git a/www/cxx_status.html b/www/cxx_status.html index 664e452987..5c57f913ab 100644 --- a/www/cxx_status.html +++ b/www/cxx_status.html @@ -578,7 +578,7 @@ welcome!</p> </tr>
<tr>
<td> 5.2.10 [expr.reinterpret.cast]</td>
- <td class="complete" align="center">✓</td>
+ <td class="complete" align="center">✓</td>
<td class="advanced" align="center"></td>
<td class="advanced" align="center"></td>
<td></td>
@@ -586,11 +586,11 @@ welcome!</p> </tr>
<tr>
<td> 5.2.11 [expr.const.cast]</td>
- <td class="complete" align="center">✓</td>
- <td class="advanced" align="center"></td>
- <td class="advanced" align="center"></td>
+ <td class="complete" align="center">✓</td>
+ <td class="complete" align="center">✓</td>
+ <td class="complete" align="center">✓</td>
+ <td></td>
<td></td>
- <td>Missing member pointer conversions</td>
</tr>
<tr><td> 5.3 [expr.unary]</td><td></td><td></td><td></td><td></td><td></td></tr>
<tr><td> 5.3.1 [expr.unary.op]</td><td></td><td></td><td></td><td></td><td></td></tr>
|