[Issue 20734] New: Array literals as arguments to scope slice parameters should be stack-allocated

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon Apr 13 14:36:31 UTC 2020


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

          Issue ID: 20734
           Summary: Array literals as arguments to scope slice parameters
                    should be stack-allocated
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: kinke at gmx.net

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.

--


More information about the Digitalmars-d-bugs mailing list