[Issue 21586] Struct dtor is called twice if struct is created inside ternary operator
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Tue Jan 26 23:38:09 UTC 2021
https://issues.dlang.org/show_bug.cgi?id=21586
moonlightsentinel at disroot.org changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |moonlightsentinel at disroot.o
| |rg
--- Comment #1 from moonlightsentinel at disroot.org ---
Modified:
extern (C) int printf(scope const char*, ...);
struct S
{
this(int arg)
{
a = arg;
printf("this(%d), this = %p\n", a, &this);
}
~this()
{
printf("~this(%d), this = %p\n", a, &this);
}
int a;
}
void main()
{
auto s = true ? S(1) : S(0);
printf("main\n");
}
----
this(1), this = 0x7fff3b745b88
~this(1), this = 0x7fff3b745b88
main
~this(1), this = 0x7fff3b745b98
---
So there's only one dtor call for the temporary created inside of the ternary
operator and another call for the variable s at the end of main.
--
More information about the Digitalmars-d-bugs
mailing list