Comment #0 by iamthewilsonator — 2019-06-14T08:05:25Z
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.
Comment #1 by iamthewilsonator — 2019-06-14T08:09:45Z
Bleaugh. That should be
auto dg2 = delegate int() const { return *p++; };
Comment #2 by iamthewilsonator — 2019-06-14T08:10:19Z
Bleaugh. That should be
auto dg2 = delegate int() const { return *p++; };
Comment #4 by iamthewilsonator — 2019-06-17T12:55:12Z
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
}
}
Comment #5 by robert.schadek — 2024-12-13T19:03:57Z