Bug 18129 – Function parameter 'scope' does not mean without @safe

Status
RESOLVED
Resolution
DUPLICATE
Severity
minor
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Mac OS X
Creation time
2017-12-26T12:30:43Z
Last change time
2018-03-16T20:06:27Z
Assigned to
No Owner
Creator
sobaya007

Comments

Comment #0 by sobaya007 — 2017-12-26T12:30:43Z
The document says that function parameter 'scope' prevents pointer from escaping. But dmd allows it without @safe. My test case here. ``` import std.stdio; int[] x; void func(scope int[] a) { x = a; } void main() { func([0,1,2]); writeln(x); } ``` Above code was successfully compiled. This behavior is not written in document. I think any explanation about it should be written.
Comment #1 by john.michael.hall — 2018-03-16T19:39:46Z
This may be related to issue 6931 [1]. Regardless, I tried simpler and some more complex variations on what you did and also got the same result. [1] https://issues.dlang.org/show_bug.cgi?id=6931
Comment #2 by issues.dlang — 2018-03-16T19:50:17Z
Without -dip1000, scope is ignored on parameters for everything other than delegates. DIP 1000 is expanding on scope to fully implement it for pointers and dynamic arrays and whatnot, but without DIP 1000, it does almost nothing. *** This issue has been marked as a duplicate of issue 6931 ***
Comment #3 by john.michael.hall — 2018-03-16T19:58:22Z
Jonathan, I was a little hesitant to say I was sure it was a duplicate of that one because I tried running it on run.dlang.org with the -dip1000 flag and it was still not giving a warning.
Comment #4 by issues.dlang — 2018-03-16T20:04:28Z
As I understand it, -dip1000 has no effect on code that isn't @safe. So, you're not going to have the compiler yelling at you over it if you're not using @safe. Either way, without -dip1000, scope on parameters only affects delegates and thus has no effect on the code posted here.
Comment #5 by john.michael.hall — 2018-03-16T20:06:27Z
Ah, you're right. It says "Errors for scope violations are only reported in @safe code."