]> git.llucax.com Git - software/eventxx.git/commitdiff
Avoid a weird gcc warning when compiling with optimizations.
authorLeandro Lucarella <llucarella@integratech.com.ar>
Fri, 21 Sep 2007 16:28:44 +0000 (13:28 -0300)
committerLeandro Lucarella <llucarella@integratech.com.ar>
Fri, 21 Sep 2007 16:28:44 +0000 (13:28 -0300)
When compiling with -O (or greater) with gcc (4.1.2 at least), there where
some warnings about "dereferencing type-punned pointer will break
strict-aliasing rules". A temporary varible to hold the pointer in the
ugly cast fix it.

eventxx

diff --git a/eventxx b/eventxx
index 9ac878d488b0f5cc8da37d87147549038af9c325..7b4d950d087255d735fb7a550f32d8b0a8fd0d21 100644 (file)
--- a/eventxx
+++ b/eventxx
@@ -201,7 +201,9 @@ inline
 type operator| (const type& t1, const type& t2)
 {
        int r = static_cast< int >(t1) | static_cast< int >(t2);
-       return *reinterpret_cast< type* >(&r);
+       int* pr = &r; // Avoid some weird warning about dereferencing
+                     // type-punned pointer will break strict-aliasing rules
+       return *reinterpret_cast< type* >(pr);
 }
 
 
@@ -320,7 +322,10 @@ struct event: basic_event
                        F& handler = *reinterpret_cast< F* >(h);
                        // Hackish, but this way the handler can get a clean
                        // event type
-                       handler(fd, *reinterpret_cast< type* >(&ev));
+                       short* pev = &ev; // Avoid some weird warning about
+                                         // dereferencing type-punned pointer
+                                         // will break strict-aliasing rules
+                       handler(fd, *reinterpret_cast< type* >(pev));
                }
 
 }; // struct event< F >