[phobos] Fwd: Re: Ruling out arbitrary cost copy construction?

Jonathan M Davis jmdavisProg at gmx.com
Wed Nov 3 10:37:37 PDT 2010


On Wednesday, November 03, 2010 10:09:03 SHOO wrote:
> (2010/11/03 2:47), Michel Fortin wrote:
> > Le 2010-11-02 à 13:05, SHOO a écrit :
> >> Another viewpoint.
> >> 
> >> Is SealedRange really appropriate?
> >> 
> >> All these are caused by the same problem:
> >> - http://ideone.com/x1Zus
> >> - http://ideone.com/iM18Q
> >> - http://ideone.com/TTin3
> >> - http://ideone.com/x4b0o
> >> 
> >> We should consider that we grope the common solution for these problems.
> >> It is the method that block the access to reference data of which
> >> instance was deleted.
> > 
> > In first and second examples, you're taking the address of a local
> > variable. This is forbidden in @safe code, so I consider this already
> > solved.
> 
> I don't think so.
> @safe code cannot forbid to bring out the address:
> http://ideone.com/rMl5i
> 
> @safe only forbid pointer operation:
> http://ideone.com/8nWRP

If you're basing that on what the compiler currently complains about, then I'm 
not sure that that's a very good measurement since @safe, @trusted, and @system 
still need a fair bit of work, as I understand it, before they're really going 
to be correct. So, even if you can currently do something in @safe mode, that 
doesn't mean that you should be able to, and if you can't do something in @safe 
mode, that doesn't necessarily mean that you're not supposed to be able to 
either.

> Rather I am strong in interest about this problem.
> I think that RAII is a main reason that a constructor and a copy
> constructor and a destructor were added to struct.
> I suspect that it is the root of all evils that D cannot handle RAII well.

I don't know if it's the root of _all_ evil, but I agree that it's a serious 
problem. Unfortunately, we'd probably need to change the language so that a 
struct's init wasn't completely known at compile-time but rather was partially 
computed at runtime if we want to _really_ solve the problem, and I question 
that we'll ever get Walter to sign off on that one. However, the lack of default 
constructors for structs is one of - if not _the_ - largest design flaw in the 
language IMO.

- Jonathan M Davis


More information about the phobos mailing list