Uncallable delegates

Walter Bright newshound2 at digitalmars.com
Wed May 13 04:41:37 UTC 2026


On 5/12/2026 7:31 PM, FeepingCreature wrote:
> ```
> @safe:
> 
> class C {
>    int x;
>    void foo() const { meep(); }
> }
> 
> C c;
> void meep() { c.x ++; }
> 
> void main() {
>    auto c = new C;
>    .c = c;
>    c.foo; // c.x mutates as an effect of a const call!
> }
> ```
> 
> As far as I can tell this is totally unstoppable as global functions don't have 
> const anyways. We'd need to consider the global scope as an implicit parameter 
> so that it could be covered by constness even with global functions.

A const reference to something can also have a mutable reference to it at the 
same time. meep() is using a mutable path to c.


More information about the dip.development mailing list