Resolve GCC's 'type-punned pointer will break strict-aliasing rules' warning by breaking up code in wxAny GetValue() and SetValue() functions into several lines (fixes #11865)

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@63850 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Jaakko Salli 2010-04-04 15:22:43 +00:00
parent 63d690d7c5
commit 1237a25bc4

View File

@ -182,7 +182,11 @@ public:
static const T& GetValue(const wxAnyValueBuffer& buf)
{
return *(reinterpret_cast<const T*>(&buf.m_buffer[0]));
// Breaking this code into two lines should supress
// GCC's 'type-punned pointer will break strict-aliasing rules'
// warning.
const T* value = reinterpret_cast<const T*>(&buf.m_buffer[0]);
return *value;
}
};
@ -323,13 +327,17 @@ public: \
virtual ~wxAnyValueTypeImpl() { } \
static void SetValue(const T& value, wxAnyValueBuffer& buf) \
{ \
*(reinterpret_cast<UseDataType*>(&buf.m_buffer[0])) = \
static_cast<UseDataType>(value); \
void* voidPtr = reinterpret_cast<void*>(&buf.m_buffer[0]); \
UseDataType* dptr = reinterpret_cast<UseDataType*>(voidPtr); \
*dptr = static_cast<UseDataType>(value); \
} \
static T GetValue(const wxAnyValueBuffer& buf) \
{ \
return static_cast<T>( \
*(reinterpret_cast<const UseDataType*>(&buf.m_buffer[0]))); \
const void* voidPtr = \
reinterpret_cast<const void*>(&buf.m_buffer[0]); \
const UseDataType* sptr = \
reinterpret_cast<const UseDataType*>(voidPtr); \
return static_cast<T>(*sptr); \
} \
};