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 | 41f4431f3989ff23029eaf2ad947f07e39fb268c (patch) | |
tree | 412f395a2e6100b60833bb3488be67eda0428351 /test/SemaCXX/reinterpret-cast.cpp | |
parent | 3c0e80e9f2f733b7b56251e9bfd4c1097a81b2f5 (diff) |
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.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@149664 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/SemaCXX/reinterpret-cast.cpp')
-rw-r--r-- | test/SemaCXX/reinterpret-cast.cpp | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/test/SemaCXX/reinterpret-cast.cpp b/test/SemaCXX/reinterpret-cast.cpp index 68005a5270..7f41b93a46 100644 --- a/test/SemaCXX/reinterpret-cast.cpp +++ b/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. |