diff options
Diffstat (limited to 'gcc/testsuite/gdc.test/runnable/test19393.d')
-rw-r--r-- | gcc/testsuite/gdc.test/runnable/test19393.d | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/gcc/testsuite/gdc.test/runnable/test19393.d b/gcc/testsuite/gdc.test/runnable/test19393.d new file mode 100644 index 00000000000..4226bbd402c --- /dev/null +++ b/gcc/testsuite/gdc.test/runnable/test19393.d @@ -0,0 +1,37 @@ +string result; + +struct S +{ + this(this) + { + result ~= "A"; + } + + ~this() + { + result ~= "B"; + } +} + +void foo(const(S)[] ar...) +{ + /* postblit gets called on this initialization, + * then when the function returns, the destructor + * gets called => result = "AB"; + */ + auto d = ar[0]; +} + +void bar() +{ + /* S(null) needs to be destroyed after the function call, + * that means that another `B` is appended => result = "ABB" + */ + foo(S()); +} + +void main() +{ + bar(); + assert(result == "ABB"); +} |