[Issue 14696] destructor for temporary called before statement is complete with ternary operator and alias this

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Tue Jun 16 13:19:58 PDT 2015


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

Walter Bright <bugzilla at digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bugzilla at digitalmars.com

--- Comment #3 from Walter Bright <bugzilla at digitalmars.com> ---
A simpler demonstration:

import core.stdc.stdio;

struct S {
    this(int i) {
        c = 's';
        p = &c;
    }

    ~this() {
        printf("S.dtor\n");
        c = 'd';
    }

    char *p;
    char c = 's';
}

int main() {
    char t = 't';
    char *q = &t;
    int x = 1;
    char *p = x ? S(1).p : q;
    printf("*p = %c\n", *p);
    assert(*p == 's');
    return 0;
}

--


More information about the Digitalmars-d-bugs mailing list