This currently fails to compile:
void foo() nothrow @safe @nogc
{
int[5] a = [ 1, 2, 3, 4, 5 ];
_d_assert_fail!("==")(a, [ 1, 2, 3, 4, 5 ]); // fails: non-nogc
}
// void _d_assert_fail!("==")(ref const(int[5]) a, scope const(int[]) b)
void _d_assert_fail(string comp, A, B)(auto ref const scope A a, auto ref const scope B b)
{}
The problem is that the array literal is needlessly allocated by the GC, although _d_assert_fail is not going to escape any reference to its data, and a stack allocation would do just fine, making this work for -betterC as well as eliminating one hurdle towards compiling the Phobos unittests with -checkaction=context.
Comment #1 by dlang-bot — 2020-04-14T12:23:40Z
@kinke created dlang/dmd pull request #11039 "Fix issue 20734 - Allocate array literals as arguments to scope slice parameters on the stack" fixing this issue:
- Fix issue 20734 - Allocate array literals as arguments to scope slice parameters on the stack
https://github.com/dlang/dmd/pull/11039
Comment #2 by dlang-bot — 2020-04-15T18:31:22Z
dlang/dmd pull request #11039 "Fix issue 20734 - Allocate array literals as arguments to scope slice parameters on the stack" was merged into master:
- f551f1b810d798a9ea9222e7e228ede32a90b6c2 by Martin Kinkelin:
Fix issue 20734 - Allocate array literals as arguments to scope slice parameters on the stack
https://github.com/dlang/dmd/pull/11039
Comment #3 by pro.mathias.lang — 2020-05-10T06:40:59Z
*** Issue 11657 has been marked as a duplicate of this issue. ***