[Issue 20116] Wrong delegate type when taking address of inout member function
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Fri Aug 16 12:08:26 UTC 2019
https://issues.dlang.org/show_bug.cgi?id=20116
--- Comment #6 from Simen Kjaeraas <simen.kjaras at gmail.com> ---
The only case in which you should be able to make an inout delegate would be
inside an inout function, with a context that is inout, and it would convert to
the correct constancy upon leaving that function. Consider this code:
class C {
int[] _arr;
auto fun() inout {
return _arr;
}
auto dgfun() inout {
auto f = () => _arr;
return f;
}
}
typeof(&(new C).dgfun) should be int[] delegate() delegate(), even though the
type of f inside dgfun should be inout(int[]) delegate() inout.
There's also the case of &C.fun - taking the address of a member function
without a context. This is already messed up in D today*, but should return
inout(int[]) function(inout(C)). Thus, the constancy of the return value
depends on the context passed to the function.
* it returns inout(int[]) function() inout, which doesn't take a C in any way,
shape or form, and is an almost foolproof recipe for memory corruption. It's
also an inout function without a context for the inout to apply to, which is
just plain broken. Don't use it unless you absolutely have to.
--
More information about the Digitalmars-d-bugs
mailing list