poll about delete
Andrei Alexandrescu
SeeWebsiteForEmail at erdani.org
Tue Jul 27 15:16:12 PDT 2010
bearophile wrote:
> Andrei Alexandrescu:
>> Agreed. I know how to fix it.
>
> Can you tell the idea?
Either define an explicit Scope type, or use the alloca() as a default
parameter trick.
> Another thing: currently somewhere in DMD there is some code that tests against returning a scoped object:
>
> class Foo {}
> Foo bar() {
> scope Foo f = new Foo;
> return f;
> }
> void main() {}
>
> That code generates the error:
> test.d(4): Error: escaping reference to scope local f
>
> While currently this doesn't generate a compile-time error:
>
> class Foo {}
> Foo bar() {
> Foo f = scoped!Foo();
> return f;
> }
> void main() {}
>
> This bug report shows that 'scoped' can cause other bugs:
> http://d.puremagic.com/issues/show_bug.cgi?id=4214
>
> But catching some of the most common bugs is positive, so can the code present in dmd used to catch and avoid the return of a scoped object be used to avoid the return of the library-defined scoped!() object?
>
> Bye,
> bearophile
I think with memory safety it's a 0/1 proposition. The current "scope"
keyword being "somewhat pregnant" is worse than not at all because it
lulls its user into a false sense of security.
Andrei
More information about the Digitalmars-d
mailing list