src: introduce upx::ptr_reinterpret_cast

This commit is contained in:
Markus F.X.J. Oberhumer
2023-10-29 16:52:24 +01:00
parent cd1df6f6b1
commit 38a676f6f7
5 changed files with 42 additions and 4 deletions
+20
View File
@@ -88,6 +88,26 @@ ACC_COMPILE_TIME_ASSERT_HEADER(compile_time::string_le("abc", "abz"))
// util
**************************************************************************/
TEST_CASE("ptr_reinterpret_cast") {
using upx::ptr_reinterpret_cast;
byte *an = nullptr;
int *in = nullptr;
CHECK((an == ptr_reinterpret_cast<byte *>(an)));
CHECK((an == ptr_reinterpret_cast<byte *>(in)));
CHECK((in == ptr_reinterpret_cast<int *>(an)));
CHECK((in == ptr_reinterpret_cast<int *>(in)));
const byte *ac = nullptr;
const int *ic = nullptr;
CHECK((ac == ptr_reinterpret_cast<byte *>(an)));
CHECK((ac == ptr_reinterpret_cast<const byte *>(ac)));
CHECK((ac == ptr_reinterpret_cast<byte *>(in)));
CHECK((ac == ptr_reinterpret_cast<const byte *>(ic)));
CHECK((ic == ptr_reinterpret_cast<int *>(an)));
CHECK((ic == ptr_reinterpret_cast<const int *>(ac)));
CHECK((ic == ptr_reinterpret_cast<int *>(in)));
CHECK((ic == ptr_reinterpret_cast<const int *>(ic)));
}
TEST_CASE("noncopyable") {
struct Test : private upx::noncopyable {
int v = 1;