Is this a violation of const?

Andrey Zherikov andrey.zherikov at gmail.com
Fri Jul 29 21:56:20 UTC 2022


In the example below `func` changes its `const*` argument. Does 
this violates D's constness?

```d
import std;

struct S
{
     string s;

     void delegate(string s) update;
}

void func(const S* s)
{
     writeln(*s);
     s.update("func");
     writeln(*s);
}

void main()
{
     auto s = S("test");
     s.update = (_) { s.s = _; };

     writeln(s);
     func(&s);
     writeln(s);
}
```

The output is:
```
S("test", void delegate(string))
const(S)("test", void delegate(string))
const(S)("func", void delegate(string))
S("func", void delegate(string))
```


More information about the Digitalmars-d-learn mailing list