[Issue 24432] New: Array dup ignores copy constructor with qualified argument
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Fri Mar 8 15:15:00 UTC 2024
https://issues.dlang.org/show_bug.cgi?id=24432
Issue ID: 24432
Summary: Array dup ignores copy constructor with qualified
argument
Product: D
Version: D2
Hardware: All
OS: All
Status: NEW
Severity: normal
Priority: P1
Component: druntime
Assignee: nobody at puremagic.com
Reporter: snarwin+bugzilla at gmail.com
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.
--
More information about the Digitalmars-d-bugs
mailing list