Bug 3566 – scoped class's member available after delete

Status
RESOLVED
Resolution
WONTFIX
Severity
major
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Linux
Creation time
2009-12-02T09:47:56Z
Last change time
2018-10-19T05:04:46Z
Assigned to
No Owner
Creator
garick

Comments

Comment #0 by garick_home_333 — 2009-12-02T09:47:56Z
---------- code: import std.stdio; class A { int v_; this( int v ) { v_ = v; } ~this() { writeln( "dtor called: ", v_ ); } } void f() { scope A a = new A( 4 ); delete a; if( a is null ) writeln( ">>> a4 is null" ); a.v_ = 500; writeln( "a.v_ == ", a.v_ ); } void main() { f(); writeln( "end main" ); } ---------- output: dtor called: 4 a.v_ == 500 end main "a" must be null after delete.. is this behavior correct ?
Comment #1 by pro.mathias.lang — 2018-10-19T05:04:46Z
There would be no way to ensure this, since it would be trivial to just copy the reference to the class and use that instead. In general, accessing `delete`d ressources is UB. Just like accessing `free`d memory. Moreover, `delete` have been deprecated, so I'm going to close this as WONTFIX.