Comment #0 by snarwin+bugzilla — 2024-03-08T15:15:00Z
As of DMD 2.107.1, the following program fails to compile:
---
struct S
{
int* dummy;
this(ref immutable S) {}
}
void main()
{
immutable(S) s1;
S s2 = s1; // ok
auto arr1 = [immutable(S)()];
auto arr2 = arr1.dup; // error
}
---
The error message is:
---
bug.d(13): Error: none of the overloads of template `object.dup` are callable using argument types `!()(immutable(S)[])`
/usr/include/dmd/druntime/import/object.d(3007): Candidates are: `dup(T : V[K], K, V)(T aa)`
/usr/include/dmd/druntime/import/object.d(3045): `dup(T : V[K], K, V)(T* aa)`
/usr/include/dmd/druntime/import/object.d(3835): `dup(T)(T[] a)`
with `T = immutable(S)`
must satisfy the following constraint:
` !is(const(T) : T)`
/usr/include/dmd/druntime/import/object.d(3858): `dup(T)(const(T)[] a)`
with `T = S`
must satisfy the following constraint:
` is(const(T) : T)`
---
dup should be able to create a mutable copy of an immutable S using the appropriately-qualified copy constructor. However, it fails to do so, because its template constraint is too strict.
This bug was originally reported in issue 20879.
Comment #1 by robert.schadek — 2024-12-07T13:43:20Z