www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - overzealous pointsTo()

reply "Nick Voronin" <elfy.nv gmail.com> writes:
pointsTo() tries to check every member of anonymous union inside struct.

import std.exception;

union U
{
	int i;
	string s;
}

struct S1
{
	int type;
	U u;
}
struct S2
{
	int type;
	union {
		int i;
		string s;
	}
}

void main()
{
	S1 s1;
	s1.u.i = 0x7FFF_FFFF;
	S2 s2;
	s2.i = 0x7FFF_FFFF;
	assert(!pointsTo(s1, s1)); // pass, pointsTo does not look into union
	assert(!pointsTo(s2, s2)); // fails because pointsTo tries to check every  
member of anonymous union
}

IMHO it should ignore unions, anonymous or not, checking every member of  
them just doesn't make sense.

-- 
Using Opera's revolutionary email client: http://www.opera.com/mail/
Dec 12 2010
parent "Nick Voronin" <elfy.nv gmail.com> writes:
On Sun, 12 Dec 2010 22:36:03 +0300, Nick Voronin <elfy.nv gmail.com> wrote:

 pointsTo() tries to check every member of anonymous union inside struct.

alias this makes a passable workaround though. (I hope) :) union U { int i; string s; } struct S3 { int type; U u; alias u this; } void main() { S3 s3; s3.i = 0x7FFF_FFFF; assert(!pointsTo(s3, s3)); // pass } -- Using Opera's revolutionary email client: http://www.opera.com/mail/
Dec 12 2010