Escaping the Tyranny of the GC: std.rcstring, first blood

Rainer Schuetze via Digitalmars-d digitalmars-d at puremagic.com
Mon Sep 15 16:49:51 PDT 2014



On 15.09.2014 10:24, Andrei Alexandrescu wrote:
>>
>> Hmm, seems fine when I try it. It feels like a bug in the type system,
>> though: when you make a copy of const(RCXString) to some RCXString, it
>> removes the const from the referenced RCBuffer struct mbuf!?
>
> The conversion relies on pure constructors. As I noted in the opening
> post, I also think there's something too lax in there. If you have a
> reduced example that shows a type system breakage without cast, please
> submit.

Here's an example:

module module2;

struct S
{
	union
	{
		immutable(char)* iptr;
		char* ptr;
	}
}

void main()
{
	auto s = immutable(S)("hi".ptr);
	S t = s;
	t.ptr[0] = 'A';
}

It seems the union is hiding the fact that there are mutable references. 
Only the first field is verified when copying the struct. Is this by 
design? (typeof(s.ptr) is "immutable(char*)")


More information about the Digitalmars-d mailing list