[Issue 18788] static arrays with a length specified at runtime should dynamically allocate on the stack

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Aug 14 21:04:00 UTC 2018


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

Walter Bright <bugzilla at digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bugzilla at digitalmars.com

--- Comment #7 from Walter Bright <bugzilla at digitalmars.com> ---
(In reply to Mike Franklin from comment #0)
>     char[newLen + 1] buf;     // Error: variable newLen cannot be read at
> compile time

I suspect the correct way to handle this would be:

    scope char[] buf = new char[newlen + 1];

The `scope` will ensure `buf` does not escape the stack frame, and so the
compiler can allocate it on the stack.

This is how:

    class C { ... }
    scope C c = new C();

works today.

--


More information about the Digitalmars-d-bugs mailing list