Bug 24432 – Array dup ignores copy constructor with qualified argument

Status
NEW
Severity
normal
Priority
P1
Component
druntime
Product
D
Version
D2
Platform
All
OS
All
Creation time
2024-03-08T15:15:00Z
Last change time
2024-12-07T13:43:20Z
Assigned to
No Owner
Creator
Paul Backus
See also
https://issues.dlang.org/show_bug.cgi?id=23563, https://issues.dlang.org/show_bug.cgi?id=23556, https://issues.dlang.org/show_bug.cgi?id=20879
Moved to GitHub: dmd#17212 →

Comments

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
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/17212 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB