www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 14122] New: GITHEAD -- Coner case regression with alias this

https://issues.dlang.org/show_bug.cgi?id=14122

          Issue ID: 14122
           Summary: GITHEAD -- Coner case regression with alias this and
                    exceptions
           Product: D
           Version: unspecified
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: regression
          Priority: P1
         Component: DMD
          Assignee: nobody puremagic.com
          Reporter: puneet coverify.org

I am getting errors with my application that runs fine with release 2.066.1

I do not know if the error is due to some race conditions in my code. While I
am refactoring my code to avoid this issue, I am filing this issue since it
could be a regression in DMD.

I tried reducing, but am not able to reduce it more. So I am pasting the 60
line code that reproduces the regression. BTW, my original code is not this
bad, much of ugliness in the snippet below arose while trying to reduce the
issue. :-)

///////////////

struct FOOW {
  FOO _foo;
  FOO foo() {
    return _foo;
  }
  alias foo this;
  this(FOO b) {
    _foo = b;
  }
}
struct FOO {
  Bar root;
  ~this() {
    if (root) {
      assert(refcou != 0);
      refcou--;
    }
  }
  this(this) {
    refcou++;
  }
}
uint refcou;
Bar bar;
class FooVec {
  FOO[] _foos;
  this() {
    for(int n ; n < 32 ; n++)
      _foos ~= FOO(bar);
  }
  FOO excp_loop(FooVec r) {
    for(size_t n; n < 32; ++n)
      excp();
    FOOW p = FOO(bar);
    return p;
  }
  void excp() {
    int[][] llll ;
    try {auto vv = llll[0][0];}
    catch {}
  }
}
class Bar {
  this() {bar = this;}
}

void main()
{
  import std.stdio;
  Bar bar = new Bar();
  for (size_t i=0; i!=16; ++i) {
      auto vec = new FooVec();
      vec.excp_loop(vec);
      writeln("Loop: ", i);
    }
  writeln("DONE");
}

--
Feb 03 2015