struct S2
{
this(int) const {}
int* i;
}
void main()
{
S2 s2 = S2(5);
}
Error: constructor `const_ctor.S2.this(int __param_0) const` is not callable using argument types `(int)`
Which is confusing as the only parameter the user sees does actually match correctly. It should instead say:
Error: `const` constructor `const_ctor.S2.this` cannot construct a mutable object
Which is the style of wording you get if the constructor is declared as immutable (actually after issue #24247 is fixed, but even without that the status quo is for immutable is much better than for const).
PR incoming.
Comment #1 by dlang-bot — 2023-11-16T19:45:05Z
@ntrel created dlang/dmd pull request #15827 "Fix Issue 24248 - const constructor call with mutable target gives wrong error message" fixing this issue:
- Fix Issue 24248 - const constructor call with mutable target gives wrong error message
https://github.com/dlang/dmd/pull/15827
Comment #2 by dlang-bot — 2023-11-18T00:40:49Z
dlang/dmd pull request #15827 "Fix Issue 24248 - const constructor call with mutable target gives wrong error message" was merged into master:
- 9c9b764e0f9fd55734ebed393f59cf87257ebb63 by Nick Treleaven:
Fix Issue 24248 - const constructor call with mutable target gives wrong error message
https://github.com/dlang/dmd/pull/15827