module test;
import std.stdio;
class buffer(T, size_t sz) {
auto arr = new T[sz];
enum end = sz-1;
}
void foo(T, size_t sz)() {
auto buf = new buffer!(T,sz);
writeln(before , buf.arr);
foreach(ref ele; buf.arr) ++ele;
writeln(after , buf.arr);
}
Whoops, that is writeln(a ,a.arr); and so on.
This looks like an optimizer bug. Do you see the same result
with -release set vs. not, etc?
On Thursday, 31 July 2014 at 18:51:09 UTC, Sean Kelly wrote:
This looks like an optimizer bug. Do you see the same result
with -release set vs. not, etc?
I get it regardless of -release or -O.
Replacing the arr declaration with T[sz] arr; fixes the problem.
On Thursday, 31 July 2014 at 18:30:41 UTC, Anonymous wrote:
module test;
import std.stdio;
class buffer(T, size_t sz) {
auto arr = new T[sz];
This allocates an array with `sz` elements once _at compile
time_, places it somewhere into the executable, and uses its
address as the
Marc Schütz:
class buffer(T, size_t sz) {
auto arr = new T[sz];
This allocates an array with `sz` elements once _at compile
time_, places it somewhere into the executable, and uses its
address as the default initializer for the member `arr`.
Right. It's not a compiler bug. Dmd/ldc
On Thursday, 31 July 2014 at 19:28:24 UTC, Marc Schütz wrote:
On Thursday, 31 July 2014 at 18:30:41 UTC, Anonymous wrote:
module test;
import std.stdio;
class buffer(T, size_t sz) {
auto arr = new T[sz];
This allocates an array with `sz` elements once _at compile
time_, places it