[Issue 24368] New: destruction of parameter should be done by caller

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sat Feb 3 19:13:38 UTC 2024


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

          Issue ID: 24368
           Summary: destruction of parameter should be done by caller
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: bugzilla at digitalmars.com

Consider:

struct TT { int a; ~this(); }

void testtt(TT tt) /* tt is actually passed by ref */
{
   tt.a = 40;
   /* tt is destructed here, g++ destructs it in caller */
}

void foot()
{
    TT t;
    t.a = 3;
    testtt(t); /* a copy of t is made here, and passed by ref */
    /* g++ destructs copy here */
}

What dmd is doing is not wrong, it just is not what g++ is doing. I do not know
why this is not showing up as a bug at least with g++ ABI compatibility.

--


More information about the Digitalmars-d-bugs mailing list