DIP25 draft available for destruction

Johannes Pfau nospam at example.com
Wed Feb 6 23:41:53 PST 2013


Am Wed, 06 Feb 2013 23:45:51 +0100
schrieb Robert <jfanatiker at gmx.at>:

> What happened to the scope storage class for parameters.
> 
> Wouldn't this solve the problems, with the simple rule that you are
> not allowed to pass transient objects by reference if the parameter
> was not declared with scope? And if I understood correctly, the
> compiler is already capable of locally ensuring that the address does
> not escape (to ensure the scope requirement), so we are all set?

This is an important question. How would this new proposal interact with
scope parameters?

Scope parameters could at least:
* Allow some otherwise trusted code to be safe:
---------
@trusted bool parse1(ref double v) {
    // Use C's scanf
    return scanf("%f", addressOf(v)) == 1; // Fine
}
---------
can be @safe if scanf parameters are scope parameters. Ditto for the
parse2 example with addressOf.

* Taking the address of a stack variable or a ref parameter could be
  allowed and @safe as long as it's only passed as scope parameters.
  (All examples in "Taking address" could work if scanf were using
  scope parameters)


IIRC the main problem with scope parameters was that escape analysis
isn't implemented yet.
http://d.puremagic.com/issues/show_bug.cgi?id=6931


More information about the Digitalmars-d mailing list