From 1237a25bc49396fa39516846a855bf3b0a4fe1f7 Mon Sep 17 00:00:00 2001 From: Jaakko Salli Date: Sun, 4 Apr 2010 15:22:43 +0000 Subject: [PATCH] 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 --- include/wx/any.h | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/include/wx/any.h b/include/wx/any.h index 26f36e7c68..c82daa1c1a 100644 --- a/include/wx/any.h +++ b/include/wx/any.h @@ -182,7 +182,11 @@ public: static const T& GetValue(const wxAnyValueBuffer& buf) { - return *(reinterpret_cast(&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(&buf.m_buffer[0]); + return *value; } }; @@ -323,13 +327,17 @@ public: \ virtual ~wxAnyValueTypeImpl() { } \ static void SetValue(const T& value, wxAnyValueBuffer& buf) \ { \ - *(reinterpret_cast(&buf.m_buffer[0])) = \ - static_cast(value); \ + void* voidPtr = reinterpret_cast(&buf.m_buffer[0]); \ + UseDataType* dptr = reinterpret_cast(voidPtr); \ + *dptr = static_cast(value); \ } \ static T GetValue(const wxAnyValueBuffer& buf) \ { \ - return static_cast( \ - *(reinterpret_cast(&buf.m_buffer[0]))); \ + const void* voidPtr = \ + reinterpret_cast(&buf.m_buffer[0]); \ + const UseDataType* sptr = \ + reinterpret_cast(voidPtr); \ + return static_cast(*sptr); \ } \ }; -- 2.45.2