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 length extension ignores copy constructor #17202

Open
dlangBugzillaToGithub opened this issue Dec 16, 2022 · 0 comments
Open

Array length extension ignores copy constructor #17202

dlangBugzillaToGithub opened this issue Dec 16, 2022 · 0 comments
Labels

Comments

@dlangBugzillaToGithub
Copy link

Paul Backus (@pbackus) reported this on 2022-12-16T17:33:09Z

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

Description

As of DMD 2.101.0, the following program compiles and runs successfully to completion:

---
struct S
{
    this(ref S)
    {
        assert(0);
    }
}

void main()
{
    S[] a = [ S() ];
    auto p = a.ptr;
    // extend until reallocation
    while (a.ptr == p)
        a.length = a.length + 1; // no assert    
}
---

This program should assert at runtime when the array is reallocated, but does not, because the copy constructors of the array's elements are not called.

If the copy constructor is changed to a postblit (`this(this)`), the program asserts at runtime, as expected.

See also issues 23557, 23556, and 20879, which cover array reallocations triggered by other means.
@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