dlang.org icon indicating copy to clipboard operation
dlang.org copied to clipboard

Add scope array literals to spec

Open dkorpel opened this issue 1 year ago • 4 comments

Requested here: https://github.com/dlang/dmd/pull/14562#issuecomment-1282905802

dkorpel avatar Oct 19 '22 10:10 dkorpel

Thanks for your pull request and interest in making D better, @dkorpel! We are looking forward to reviewing it, and you should be hearing from a maintainer soon. Please verify that your PR follows this checklist:

  • My PR is fully covered with tests (you can see the coverage diff by visiting the details link of the codecov check)
  • My PR is as minimal as possible (smaller, focused PRs are easier to review than big ones)
  • I have provided a detailed rationale explaining my changes
  • New or modified functions have Ddoc comments (with Params: and Returns:)

Please see CONTRIBUTING.md for more information.


If you have addressed all reviews or aren't sure how to proceed, don't hesitate to ping us with a simple comment.

Bugzilla references

Your PR doesn't reference any Bugzilla issue.

If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog.

dlang-bot avatar Oct 19 '22 10:10 dlang-bot

What about when the element type is not plain old data as mentioned in the changelog: https://github.com/dlang/dmd/pull/14562/files#diff-a773cf7a39af2594f4e2e4f8aa41047d2b2f10a8558a5f0cb1c7d4c86f6d0304R23

ntrel avatar Oct 19 '22 15:10 ntrel

What about when the element type is not plain old data as mentioned in the changelog: https://github.com/dlang/dmd/pull/14562/files#diff-a773cf7a39af2594f4e2e4f8aa41047d2b2f10a8558a5f0cb1c7d4c86f6d0304R23

As-if rule may be useful

maxhaton avatar Oct 19 '22 16:10 maxhaton

It is worth noting that this change (and others like it) may silently introduce memory corruption into any @trusted code that relied on the old behavior. For example, the following code is memory safe when compiled with DMD 2.100, but will be unsound when compiled with DMD 2.101:

@trusted int[] example()
{
    scope arr = [1, 2, 3];
    return arr;
}

pbackus avatar Oct 25 '22 02:10 pbackus