(unnamed)

text/plain

Filename: (unnamed)
Type: text/plain
Part: 0
Message: Re: warning: dereferencing type-punned pointer
/*
 * Minimum definitions copied from PostgreSQL to make the
 * test self-contained.
 */
#define nodeTag(nodeptr)  (((const Node*)(nodeptr))->type)
#define IsA(nodeptr,_type_)  (nodeTag(nodeptr) == T_##_type_)

typedef enum NodeTag
{
	T_Invalid = 0,
	T_List = 1
} NodeTag;

typedef struct Node
{
	NodeTag		type;
} Node;

/* Home brew node */
typedef struct Foo
{
	NodeTag		type;
	int		d;
} Foo;

static int	sub(void)
{
	Foo	f;
	Foo	*fp = &f;
	f.type = T_List;

	/* strict aliasing rule error */
	if (IsA(&f, List))
		return 1;

	/* This is ok */
	if (IsA(fp, List))
		return 1;
	return 0;
}