Yet Another Const Proposal

Walter Bright newshound1 at digitalmars.com
Sat Dec 8 03:00:27 PST 2007


Sönke Ludwig wrote:
> Also, an important observation:
> 
> ----
> class C {}
> struct S {
>     invariant(C) inst;
> }
> S s = S(new C);
> invariant(C)* pc = &s.inst;
> s = S(null);
> assert( *pc != null ); // fails
>   // *pc is null now, despite beeing invariant(C)*, which should
>   // mean, that the memory pointed to by pc will never change!
> ----
> 
> So to make the system semantically consistent, you'd have to forbid 
> structure
> assignments, if there are any invariant members. This in turn makes the
> TailInvariant!()-solution impossible without severly hacking around the 
> type
> system.

I hadn't thought of that. Good catch.



More information about the Digitalmars-d mailing list