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

Closed
jmdavis opened this issue Mar 9, 2025 · 5 comments · Fixed by #4185

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.
jmdavis added a commit to jmdavis/dlang.org that referenced this issue Mar 18, 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 18, 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.
@TurkeyMan
Copy link
Contributor

I kinda feel like this is backwards; shouldn't the issue you describe be fixed instead of the spec being revised? That's a super-weird resolution to a bug. How do you arrive at the idea that revising the spec is the appropriate bug fix?

That said, I'm pretty horrified that copy constructors must have been added how many years ago, and you're saying they don't work? :/ .. This is just classic D! I mean, I did kinda know this because I've tried to use them and they did cause me problems, but I just assumed it was because I was doing something 'exotic'.

So, what do we do? It's almost impossible to do anything because everything is so fragile, nobody will ever do anything that addresses the overall brittle-ness, and then this hyper-conservative approach which leaves everything broken and never fix anything; it leads to people building around a broken ecosystem and depending on the quirks/bugs, and then people go "oh no, we can't fix anything because it'll break the code that was carefully adapted to the broken thing that we won't fix". Is this really where we want to be?

@rikkimax
Copy link
Contributor

For AA's they'll be fixed once the implementation is converted to a template, since the compiler can kick in then. That is supposed to be done by @schveiguy this year hopefully.

I don't remember the status of dynamic array hooks being templated. @RazvanN7

@TurkeyMan
Copy link
Contributor

Kinda feels like this is, like, maximum priority stuff? The language being in a state where you can't even successfully construct an object according to the spec is just, like, broken; in the most literal sense of the word.
It's like a "stop everything, all hands on deck until this is fixed" kinds thing... this situation shouldn't have persisted for a single day; how did this happen?

@dkorpel
Copy link
Contributor

dkorpel commented Mar 21, 2025

I think most D programmers are happily using plain structs / classes / base data types and don't care that much about postblits / copy constructors.

@TurkeyMan
Copy link
Contributor

Mm. It's really un-fun to work without decent strings, dynamic arrays, maps, general collections, etc, though. It's been a gaping hole in the library forever.

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.

4 participants