]> git.saurik.com Git - wxWidgets.git/commitdiff
Resolve GCC's 'type-punned pointer will break strict-aliasing rules' warning by break...
authorJaakko Salli <jaakko.salli@dnainternet.net>
Sun, 4 Apr 2010 15:22:43 +0000 (15:22 +0000)
committerJaakko Salli <jaakko.salli@dnainternet.net>
Sun, 4 Apr 2010 15:22:43 +0000 (15:22 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@63850 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/any.h

index 26f36e7c68a7f6a8bab6b91fd9fa5dd39602475a..c82daa1c1a5ed0d7c03c4d1a009b60d3e3f29e4c 100644 (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); \
     } \
 };