diff options
author | Chad Rosier <mcrosier@apple.com> | 2012-02-03 02:54:37 +0000 |
---|---|---|
committer | Chad Rosier <mcrosier@apple.com> | 2012-02-03 02:54:37 +0000 |
commit | 96c755d13c58487ecd1a8d0cbbd017364c1725a0 (patch) | |
tree | 285338a75e0716f000464e0eb7701de9371a830c /clang/test/SemaCXX/reinterpret-cast.cpp | |
parent | 9bb33f572f7609d469d3a505c9987b83eac5b78c (diff) | |
download | bcm5719-llvm-96c755d13c58487ecd1a8d0cbbd017364c1725a0.tar.gz bcm5719-llvm-96c755d13c58487ecd1a8d0cbbd017364c1725a0.zip |
C++ 5.2.10p2 has a note that mentions that, subject to all other restrictions,
a cast to the same type is allowed so long as it does not cast away constness.
Fix for PR11747. Patch by Aaron Ballman. Reviewed by Eli.
llvm-svn: 149664
Diffstat (limited to 'clang/test/SemaCXX/reinterpret-cast.cpp')
-rw-r--r-- | clang/test/SemaCXX/reinterpret-cast.cpp | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/clang/test/SemaCXX/reinterpret-cast.cpp b/clang/test/SemaCXX/reinterpret-cast.cpp index 68005a5270e..7f41b93a46e 100644 --- a/clang/test/SemaCXX/reinterpret-cast.cpp +++ b/clang/test/SemaCXX/reinterpret-cast.cpp @@ -9,13 +9,27 @@ typedef void (*fnptr)(); // Test the conversion to self. void self_conversion() { - // T*->T* is allowed, T->T in general not. + // T->T is allowed per [expr.reinterpret.cast]p2 so long as it doesn't + // cast away constness, and is integral, enumeration, pointer or + // pointer-to-member. int i = 0; - (void)reinterpret_cast<int>(i); // expected-error {{reinterpret_cast from 'int' to 'int' is not allowed}} - structure s; - (void)reinterpret_cast<structure>(s); // expected-error {{reinterpret_cast from 'structure' to 'structure' is not allowed}} + (void)reinterpret_cast<int>(i); + + test e = testval; + (void)reinterpret_cast<test>(e); + + // T*->T* is allowed int *pi = 0; (void)reinterpret_cast<int*>(pi); + + const int structure::*psi = 0; + (void)reinterpret_cast<const int structure::*>(psi); + + structure s; + (void)reinterpret_cast<structure>(s); // expected-error {{reinterpret_cast from 'structure' to 'structure' is not allowed}} + + float f = 0.0f; + (void)reinterpret_cast<float>(f); // expected-error {{reinterpret_cast from 'float' to 'float' is not allowed}} } // Test conversion between pointer and integral types, as in /3 and /4. |