On Tuesday, 10 October 2017 at 02:37:21 UTC, Walter Bright wrote:
On 10/9/2017 8:04 AM, Per Nordlöw wrote:
...
Get rid of the templates, too. Replace T with int. Get rid of
any of the layers of confusing complexity.
...
this looks like an issue to me. If its a template the pointer can
escape. The non-template-version doesnt let the pointer escape
@safe:
struct ST( T) {
@safe:
T[ 128] x;
scope ref T front() return {
return x[ 0];
}
scope T* pointer() return {
return &x[ 0];
}
}
ref int testFrontT() {
ST!int s;
return s.front(); // pointer escapes
}
int* testPointerT() {
ST!int s;
return s.pointer(); // pointer escapes
}
struct S {
@safe:
int[ 128] x;
scope ref int front() return {
return x[ 0];
}
scope int* pointer() return {
return &x[ 0];
}
}
ref int testFront() {
S s;
return s.front(); // error
}
int* testPointer() {
S s;
return s.pointer(); // error
}