Bug 24805 – The spec should not refer to default initialization as default construction when discussing disabling it

Status
NEW
Severity
normal
Priority
P1
Component
dlang.org
Product
D
Version
D2
Platform
All
OS
All
Creation time
2024-10-11T18:32:54Z
Last change time
2024-12-15T15:28:33Z
Keywords
spec
Assigned to
No Owner
Creator
Jonathan M Davis
Moved to GitHub: dlang.org#4146 →

Comments

Comment #0 by issues.dlang — 2024-10-11T18:32:54Z
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.
Comment #1 by nick — 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
Comment #2 by issues.dlang — 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.
Comment #3 by issues.dlang — 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.
Comment #4 by issues.dlang — 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.
Comment #5 by robert.schadek — 2024-12-15T15:28:33Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dlang.org/issues/4146 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB