[Issue 13038] New: Calling to!String in the destructor

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Thu Jul 3 20:22:17 PDT 2014


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

          Issue ID: 13038
           Summary: Calling to!String in the destructor
           Product: D
           Version: D2
          Hardware: x86
                OS: Windows
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: druntime
          Assignee: nobody at puremagic.com
          Reporter: zhnavigator at mail.ru

import std.stdio;
import std.conv;
class CDummy {
  static size_t counter; 
  this() { counter++; }

  ~this() {
   counter--;
   writeln(to!string(counter)); // <= Ok!!!
  }
}
int main(string[] argv)
{
    foreach(i; 0..10) {
        auto obj = new CDummy;
        destroy(obj);
    }
    return 0;
}
Ok!!!
//---------------------------------------------

import std.stdio;
import std.conv;
class CDummy {
  static size_t counter;     
  this() { counter++; }

  ~this() {
   counter--;
   writeln(to!string(counter)); //<==
core.exception.InvalidMemoryOperationError
  }
}

int main(string[] argv)
{
  foreach(i; 0..10) {
    auto obj = new CDummy;
    //destroy(obj);
  }
  return 0;
}
Crash!!!
core.exception.InvalidMemoryOperationError
//---------------------------------------------

import std.stdio;
import std.conv;
class CDummy {
  static size_t counter; 
  this() { counter++; }

  ~this() {
   counter--;
   writeln(counter); // <== ok
  }
}

int main(string[] argv)
{
  foreach(i; 0..10) {
   auto obj = new CDummy;
   //destroy(obj);
  }
  return 0;
}
Ok!!!

--


More information about the Digitalmars-d-bugs mailing list