[Issue 24211] Const nested function can mutate context

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Nov 2 00:53:31 UTC 2023


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

Paul Backus <snarwin+bugzilla at gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |safe

--- Comment #3 from Paul Backus <snarwin+bugzilla at gmail.com> ---
This bug creates a hole in @safe when combined with "Inferred scope parameters
in pure functions" [1].

---
void main() @safe
{
    const(int)* escaped;

    @safe pure nothrow
    void fun(const(int)* p) const
    {
        escaped = p;
    }

    int n;
    fun(&n);
}
---

Because fun's context is const, the compiler can assume that "None of the other
parameters [aside from p] have mutable indirections," and allow the use of a
scope pointer as an argument. If not for this bug, that assumption would be
correct.

[1] https://dlang.org/spec/function.html#pure-scope-inference

--


More information about the Digitalmars-d-bugs mailing list