void main() { int i = 42; // const should not be able to access mutable. int* p = &i; auto dg2 = delegate int() const { return *p; }; assert(dg2() == i); } fails to error. Also void main() { int i = 42; // shared cannot access mutable int* p = &i; auto dg2 = delegate int() shared { return *p; }; assert(dg2() == i); } errors, the context should be captured as shared so that should be allowed. Issue 15306 declared this accepts invalid as shared aliasing but I believe that is incorrect. Shared doesn't offer any useful guaruntees on that front anyway.
Bleaugh. That should be auto dg2 = delegate int() const { return *p++; };
Partial fix: https://github.com/dlang/dmd/pull/10035
So the real issue is: struct S { int x; void foo() const { pragma(msg, typeof(x)); // const(int) } } void test() { void nested() const { pragma(msg, typeof(x)); // int } }
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/17909 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB