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 not refer to default initialization as default construction when discussing disabling it #4146

Open
dlangBugzillaToGithub opened this issue Oct 11, 2024 · 4 comments

Comments

@dlangBugzillaToGithub
Copy link

Jonathan M Davis (@jmdavis) reported this on 2024-10-11T18:32:54Z

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

CC List

Description

The language allows us to disable default initialization - e.g.

---
struct S
{
    int x;

    @disable this();

    this(int v) { x = v; }
}
---

and the https://dlang.org/spec/struct.html#disable_default_construction section of the spec discusses this. However, it incorrectly talks about disabling default construction instead of discussing disabling default initialization. As default construction is not a thing with structs in D in the first place, the terminology used in this part of the spec is just plain wrong and risks confusing people. The spec should be updated to talk about disabling default initialization instead.
@dlangBugzillaToGithub
Copy link
Author

nick (@ntrel) commented on 2024-10-12T13:12:29Z

> As default construction is not a thing with structs

What about initializing the context pointer?

https://dlang.org/spec/property.html#init-vs-construction

@dlangBugzillaToGithub
Copy link
Author

issues.dlang (@jmdavis) commented on 2024-10-12T14:25:42Z

(In reply to Nick Treleaven from comment #1)
> > As default construction is not a thing with structs
> 
> What about initializing the context pointer?
> 
> https://dlang.org/spec/property.html#init-vs-construction

D structs do not have default construction, and it is always incorrect to refer to anything that happens with them as default construction. They have default initialization, which normally is simply blitting the init value, but with non-static structs that then have a context pointer to their enclosing scope, some additional initialization code is run when they're initialized to also set their context pointer, making it so that there is a difference between that and directly initializing the struct with its init value in those specific cases.

However, there still is no default constructor or default construction, and referring to it that way is just going to confuse people. Default constructors are a C++ thing, and even if we were to add them to D structs at some point, the default initialization that currently occurs would still occur prior to the default constructor being called (since that's required for the type to be in a valid state; it's also what happens with classes), so there would still be a difference between default initialization and default construction.

@dlangBugzillaToGithub
Copy link
Author

issues.dlang (@jmdavis) commented on 2024-10-13T09:48:41Z

I've e-mailed Walter for clarification on this. It appears that the compiler's error messages are in agreement with the terminology used in the spec. So, the current terminology may very well be what Walter wants to use in spite of the fact that we don't have default constructors, and we normally talk about structs being default-initialized rather than default-constructed, because we don't have default constructors, and the mechanics are different.

@dlangBugzillaToGithub
Copy link
Author

issues.dlang (@jmdavis) commented on 2024-10-14T19:31:46Z

Walter agreed to updating the terminology to refer to default initialization instead of default construction. I'll open a separate issue for the compiler messages.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant