forked from Mirrors/openclonk
Fix strict aliasing violation, make C4Real pass is_pod
parent
f03a1d618d
commit
97bdddba24
|
@ -74,8 +74,8 @@ public:
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// constructors
|
// constructors
|
||||||
inline C4Fixed () { }
|
inline C4Fixed () = default;
|
||||||
inline C4Fixed (const C4Fixed &rCpy): val(rCpy.val) { }
|
inline C4Fixed (const C4Fixed &) = default;
|
||||||
|
|
||||||
// Conversion must be done by the conversion routines itofix, fixtoi, ftofix and fixtof
|
// Conversion must be done by the conversion routines itofix, fixtoi, ftofix and fixtof
|
||||||
// in order to be backward compatible, so everything is private.
|
// in order to be backward compatible, so everything is private.
|
||||||
|
|
|
@ -240,10 +240,13 @@ struct StdCastAdapt
|
||||||
inline void CompileFunc(StdCompiler *pComp) const
|
inline void CompileFunc(StdCompiler *pComp) const
|
||||||
{
|
{
|
||||||
// Cast
|
// Cast
|
||||||
assert(sizeof(to_t) == sizeof(T));
|
static_assert(sizeof(to_t) == sizeof(T), "CastAdapt sanity: sizes match");
|
||||||
to_t vVal = *reinterpret_cast<to_t *>(&rValue);
|
static_assert(std::is_pod<to_t>::value, "CastAdapt sanity: to-type is POD");
|
||||||
|
static_assert(std::is_pod<T>::value, "CastAdapt sanity: from-type is POD");
|
||||||
|
to_t vVal;
|
||||||
|
std::memcpy(&vVal, &rValue, sizeof(to_t));
|
||||||
pComp->Value(vVal);
|
pComp->Value(vVal);
|
||||||
rValue = *reinterpret_cast<T *>(&vVal);
|
std::memcpy(&rValue, &vVal, sizeof(T));
|
||||||
}
|
}
|
||||||
// Operators for default checking/setting
|
// Operators for default checking/setting
|
||||||
template <class D> inline bool operator == (const D &nValue) const { return rValue == nValue; }
|
template <class D> inline bool operator == (const D &nValue) const { return rValue == nValue; }
|
||||||
|
|
Loading…
Reference in New Issue