Weird DIP1000 issue

Walter Bright newshound2 at digitalmars.com
Wed Feb 8 23:32:16 UTC 2023


Simplifying your example:

> ref front_p(int* p) { return *p; }
>
> void main() @safe
> {
>      int _errors;
>      front_p(&_errors); /* copy from `ref` via pointer:
>                                   fails, should work */
> }

1. &_errors is a pointer to the stack.

2. passing a pointer to the stack to front_p's `p` variable.

3. Since `p` is not declared `scope`, the compiler assumes that front_p allows 
`p` to escape. (Inference of attributes does not happen for regular functions.)

4. An escaping pointer to the stack is not allowed by dip1000 rules.


The compiler is working as expected.

Ruthlessly cutting down the example, as I did here, helps a lot to expose what 
the real problem is.




More information about the Digitalmars-d mailing list