www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 17869] New: scope class object no longer deleted when created


          Issue ID: 17869
           Summary: scope class object no longer deleted when created via
                    factory function
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Windows
            Status: NEW
          Keywords: wrong-code
          Severity: regression
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: r.sagitario gmx.de

import core.stdc.stdio;

void foo()
    scope baseKey = Key.getKey();

int main(string[] argv)
    printf("main init\n");
    printf("main exit\n");
    return 0;

class Key
    this() { printf("ctor\n"); }
    ~this() { printf("dtor\n"); }

    static Key getKey() { return new Key(); }

This prints

main init
main exit

with dmd 2.074 and

main init
main exit

with dmd 2.075+, i.e. the class instance assigned to the scope variable is
destroyed in the final collection, not in foo's scope. The 2.074 version is
according to spec IMO: "... the destructor for an object is automatically
called when the reference to it goes out of scope."

Probably introduced by https://github.com/dlang/dmd/pull/6826

Oct 01 2017