src: rename ptr_reinterpret_cast to ptr_static_cast; misc cleanups

This commit is contained in:
Markus F.X.J. Oberhumer
2023-12-20 11:44:01 +01:00
parent 3326c86e91
commit 51a6a5cca5
9 changed files with 54 additions and 50 deletions
+5 -5
View File
@@ -63,18 +63,18 @@ struct UnsignedSizeOf {
static constexpr unsigned value = unsigned(Size);
};
// a reinterpret_cast that does not trigger -Wcast-align warnings
// a static_cast that does not trigger -Wcast-align warnings
template <class Result, class From>
forceinline Result ptr_reinterpret_cast(From *ptr) noexcept {
forceinline Result ptr_static_cast(From *ptr) noexcept {
static_assert(std::is_pointer_v<Result>);
static_assert(!std::is_const_v<std::remove_pointer_t<Result> >); // enforce same constness
return reinterpret_cast<Result>(reinterpret_cast<void *>(ptr));
return static_cast<Result>(static_cast<void *>(ptr));
}
template <class Result, class From>
forceinline Result ptr_reinterpret_cast(const From *ptr) noexcept {
forceinline Result ptr_static_cast(const From *ptr) noexcept {
static_assert(std::is_pointer_v<Result>);
static_assert(std::is_const_v<std::remove_pointer_t<Result> >); // required
return reinterpret_cast<Result>(reinterpret_cast<const void *>(ptr));
return static_cast<Result>(static_cast<const void *>(ptr));
}
class noncopyable {
+1 -1
View File
@@ -159,7 +159,7 @@ inline R *xspan_make_helper__(MemBuffer &mb) noexcept {
#define XSPAN_S_VAR(type, var, first, ...) type *var = XSPAN_S_MAKE(type, (first))
// cast to a different type (creates a new value)
#define XSPAN_TYPE_CAST(type, x) (upx::ptr_reinterpret_cast<type *>(x))
#define XSPAN_TYPE_CAST(type, x) (upx::ptr_static_cast<type *>(x))
// poison a pointer: point to a non-null invalid address
#define XSPAN_INVALIDATE(x) ptr_invalidate_and_poison(x)
+2 -2
View File
@@ -284,8 +284,8 @@ public:
inline CSelf<U> type_cast() const {
typedef CSelf<U> R;
typedef typename R::pointer rpointer;
return R(R::Unchecked, upx::ptr_reinterpret_cast<rpointer>(ptr), size_in_bytes,
upx::ptr_reinterpret_cast<rpointer>(base));
return R(R::Unchecked, upx::ptr_static_cast<rpointer>(ptr), size_in_bytes,
upx::ptr_static_cast<rpointer>(base));
}
bool operator==(pointer other) const noexcept { return ptr == other; }
+1 -1
View File
@@ -127,7 +127,7 @@ public:
inline CSelf<U> type_cast() const {
typedef CSelf<U> R;
typedef typename R::pointer rpointer;
return R(upx::ptr_reinterpret_cast<rpointer>(ptr));
return R(upx::ptr_static_cast<rpointer>(ptr));
}
// comparison