------- Comment #3 from vda dot linux at googlemail dot com  2010-02-04 14:33 
-------
I was bitten by this whet I was trying to get rid of
"warning: dereferencing type-punned pointer will break strict-aliasing rules"
on this fairly normal networking-related code:

if (cmsgptr->cmsg_level == IPPROTO_IP && cmsgptr->cmsg_type == IP_PKTINFO) {
# define pktinfo(cmsgptr) ((struct in_pktinfo*)(CMSG_DATA(cmsgptr)))
    to->sa_family = AF_INET;
    memcpy(&to4->sin_addr, &pktinfo(cmsgptr)->ipi_addr, sizeof(to4->sin_addr));

I can't modify struct in_pktinfo declaration, it's in system header, so I
wanted to create a "aliasing" version of it, but this doesn't work for structs.


Distilled, the problem is that this works:

typedef int aliased_int __attribute__((__may_alias__));

but the same thing on structs does not, even if struct is hidden behind an
intermediate typedef:

struct s { int i; };
typedef struct s t;
typedef struct s aliased_s __attribute__((__may_alias__));
typedef t aliased_t __attribute__((__may_alias__));

last two typedefs both throw:

warning: ignoring attributes applied to 'struct s' after definition


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34156

Reply via email to