[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 14:08:15 PDT 2015


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

--- Comment #4 from Steven Schveighoffer <schveiguy at yahoo.com> ---
(In reply to Walter Bright from comment #3)
> struct S {
>     this(int i) {
>         c = 's';
>         p = &c;

This is not allowed, and I'm not sure it's a valid test case. You could fix by
doing this:

struct S
{
    this(ref char x){
        p = &x;
        *p = 's';
    }
    ~this() {
        if(p) *p = 'd';
        p = null;
    }
}

void main()
{
   char c = 'c';
   char o = 'o';
   int i = 1;
   writeln(*(i ? S(c).p : &o));
}

prints: d

--


More information about the Digitalmars-d-bugs mailing list