Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Array dup ignores copy constructor with qualified argument #17212

Open
dlangBugzillaToGithub opened this issue Mar 8, 2024 · 0 comments
Open
Labels

Comments

@dlangBugzillaToGithub
Copy link

Paul Backus (@pbackus) reported this on 2024-03-08T15:15:00Z

Transferred from https://issues.dlang.org/show_bug.cgi?id=24432

Description

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.
@thewilsonator thewilsonator added the Druntime Specific to druntime label Dec 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants