On Sunday, 20 October 2013 at 14:25:37 UTC, bearophile wrote:
More discussions about variable-sized stack-allocated arrays in C++, it seems there is no yet a consensus:

http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3810.pdf

I'd like variable-sized stack-allocated arrays in D.

Bye,
bearophile

I think that is a job for the optimizer. Consider cases like :

auto foo() {
    return new Foo();
}

void bar() {
   auto f = foo();
   f.someMethod();
}

This is an incredibly common pattern, and it won't be possible to optimize it via added language design without dramatic increase in language complexity.

However, once the inliner is passed, you'll end up with something like :
auto foo() {
    return new Foo();
}

void bar() {
   auto f = new Foo();
   f.someMethod();
}

And if the optimizer is aware of GC calls (LDC is already aware of them, even if only capable of limited optimizations, it is already a good start and show the feasibility of the idea).

Obviously Foo is a struct or an class here, but that is the exact same problem as for arrays.

Reply via email to