[Issue 21586] Struct dtor is called twice if struct is created inside ternary operator

d-bugmail at puremagic.com d-bugmail at puremagic.com
Wed Jan 27 11:45:50 UTC 2021


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

Boris Carvajal <boris2.9 at gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |boris2.9 at gmail.com

--- Comment #4 from Boris Carvajal <boris2.9 at gmail.com> ---
The temporary variable also disappears when there's a postblit.

AST generated when a postblit or copy constructor is present:

    S s = (true) ? s = 0 , s.this(1) : (s = 0 , s.this(0));

In the original case:

    S s = (true) ? (S(0)).this(1) : (S(0)).this(0);

Looks like a frontend bad decision, there's no reason to not generate the
equivalent code to a simple assignment. For example:

    S s = S(1);

generates:

    S s = s = 0 , s.this(1);

--


More information about the Digitalmars-d-bugs mailing list