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

The spec should warn against using copy constructors, not warn against using postblit constructors #4184

Open
jmdavis opened this issue Mar 9, 2025 · 0 comments · May be fixed by #4185
Open

Comments

@jmdavis
Copy link
Member

jmdavis commented Mar 9, 2025

Due to dlang/dmd#20970, any types with a copy constructor should not be used in a dynamic array or associative array, which realistically means that no one who isn't using -betterC should be using copy constructors.

However, the spec currently has a warning on postblit constructors, telling programmers to use copy constructors in new code instead. This might make sense if druntime supported copy constructors properly, but it doesn't. And until it does, IMHO, we really need to be warning programmers against using copy constructors and instead be telling them to use postblit constructors. Personally, I wasted a considerable amount of time because of this issue, because I did not realize that the support for copy constructors was not complete, and I'm one of the core contributors, and without the spec being correct with regards to the current state of things, plenty of other folks are going to make the same mistake.

jmdavis added a commit to jmdavis/dlang.org that referenced this issue Mar 9, 2025
…ors.

Until dlang/dmd#20970 is fixed, we need to be
warning against the use of copy constructors rather than warning
against the use of postblit constructors.

So, I fixed the warning and put both it and the description of what
happens when mixing postblit constructors and copy constructors together
on both the section for postblit constructors and the one for copy
constructors.

I suspect that move constructors merit a similar warning, but I'm not
sure what their current state is, so this just fixes the warning for
postblit constructors and copy constructors.
jmdavis added a commit to jmdavis/dlang.org that referenced this issue Mar 11, 2025
…ors.

Until dlang/dmd#20970 is fixed, we need to be
warning against the use of copy constructors rather than warning
against the use of postblit constructors.

So, I fixed the warning and put both it and the description of what
happens when mixing postblit constructors and copy constructors together
on both the section for postblit constructors and the one for copy
constructors.

I suspect that move constructors merit a similar warning, but I'm not
sure what their current state is, so this just fixes the warning for
postblit constructors and copy constructors.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant