www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 10929] New: [CTFE] Destructor errornously gets called on NRVO-ed structs?


           Summary: [CTFE] Destructor errornously gets called on NRVO-ed
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: critical
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: dmitry.olsh gmail.com

--- Comment #0 from Dmitry Olshansky <dmitry.olsh gmail.com> 2013-08-30
11:33:52 PDT ---
If CTFE did full copy with postblit and dtor-ed temporary it would be more or
less OK.. but instead it seemingly moves struct but calls dtor. 

(this bug blocks development of std.regex, marking as critical)

Test case shows difference between R-T and C-T:

struct Destroyable{
        payload = 0;
    int payload;    
    int dtorCount;
    int postblitCount;

auto make()
    auto val =  Destroyable(42, 0);
    return val;

enum dg = (){ 
    auto val = make();
    assert(val.postblitCount == 0); //passes in both modes
    assert(val.dtorCount == 1); //passes at CT -- WAT?
    //at R-T the above assertion fails as expected
    return 0;

enum test_me = dg();

int main(){    
    return dg();

Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Aug 30 2013