[cfe-commits] r63055 - in /cfe/trunk: lib/Sema/SemaNamedCast.cpp test/SemaCXX/const-cast.cpp www/cxx_status.html
Sebastian Redl
sebastian.redl at getdesigned.at
Mon Jan 26 14:19:12 PST 2009
Author: cornedbee
Date: Mon Jan 26 16:19:12 2009
New Revision: 63055
URL: http://llvm.org/viewvc/llvm-project?rev=63055&view=rev
Log:
Add support for member pointers to const_cast.
Modified:
cfe/trunk/lib/Sema/SemaNamedCast.cpp
cfe/trunk/test/SemaCXX/const-cast.cpp
cfe/trunk/www/cxx_status.html
Modified: cfe/trunk/lib/Sema/SemaNamedCast.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaNamedCast.cpp?rev=63055&r1=63054&r2=63055&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaNamedCast.cpp (original)
+++ cfe/trunk/lib/Sema/SemaNamedCast.cpp Mon Jan 26 16:19:12 2009
@@ -133,7 +133,10 @@
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 @@
<< 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.
Modified: cfe/trunk/test/SemaCXX/const-cast.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/const-cast.cpp?rev=63055&r1=63054&r2=63055&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/const-cast.cpp (original)
+++ cfe/trunk/test/SemaCXX/const-cast.cpp Mon Jan 26 16:19:12 2009
@@ -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 @@
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 @@
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;
}
Modified: cfe/trunk/www/cxx_status.html
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/www/cxx_status.html?rev=63055&r1=63054&r2=63055&view=diff
==============================================================================
--- cfe/trunk/www/cxx_status.html (original)
+++ cfe/trunk/www/cxx_status.html Mon Jan 26 16:19:12 2009
@@ -578,7 +578,7 @@
</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 @@
</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>
More information about the cfe-commits
mailing list