D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 3566 - scoped class's member available after delete
Summary: scoped class's member available after delete
Status: RESOLVED WONTFIX
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: x86 Linux
: P2 major
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-12-02 09:47 UTC by garick
Modified: 2018-10-19 05:04 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description garick 2009-12-02 09:47:56 UTC
----------
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 Mathias LANG 2018-10-19 05:04:46 UTC
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.