Bug 18628 – @disable this(this) erroneously adds `__postblit` member

Status
NEW
Severity
normal
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2018-03-18T20:31:02Z
Last change time
2024-12-13T18:57:55Z
Keywords
industry
Assigned to
No Owner
Creator
johanengelen
Moved to GitHub: dmd#17852 →

Comments

Comment #0 by johanengelen — 2018-03-18T20:31:02Z
Testcase: ``` import std.traits; import std.stdio; void main() { static struct S { @disable this(this); } writeln(hasMember!(S, "__postblit")); // expected: false writeln(hasElaborateCopyConstructor!S); // expected: false } ``` The program prints twice "true", instead of "false". Note that `hasElaborateCopyConstructor` does a `hasMember!(S, "__postblit")` check, so that's the root cause of the problem.
Comment #1 by razvan.nitu1305 — 2018-03-19T11:41:27Z
Well, the struct defines the member, it's just that it is disabled. One might argue that the output is correct and the programmer needs to check if the member is disabled or not
Comment #2 by razvan.nitu1305 — 2018-03-19T11:43:17Z
What I'm saying is that the output of hasMember is correct, but the output of hasElaborateCopyConstructor most certainly isn't, but, in my opinion, the fix should be in phobos, not in dmd.
Comment #3 by andrei — 2018-03-19T16:40:35Z
Question applies to all functions. Consider: import std.stdio; import std.traits; struct A { @disable void fun(); } void main() { writeln(hasMember!(A, "fun")); // expected: false } This prints true.
Comment #4 by andrei — 2018-03-19T16:43:10Z
The problem with hasElaborateCopyConstructor is the binary expectation: * is that true? Then there's work involved to copy the object * is that false? Then the object can be copied with memcpy This does not account for the disabled case. So I'm not sure what to do here aside from defining a different trait e.g. hasDisabledCopyConstructor.
Comment #5 by johanengelen — 2018-03-20T23:33:18Z
(In reply to RazvanN from comment #1) > Well, the struct defines the member, it's just that it is disabled. One > might argue that the output is correct and the programmer needs to check if > the member is disabled or not I strongly disagree. The `@disabled` function line does not _define_ the function (i.e. there is no implementation for it), at most it could be a _declaration_. But in fact, in my opinion, the `@disable` line explicitly says that it's not even declared, similar to C++'s "= delete". Currently, adding `@disable this(this)` to a struct that normally wouldn't have a postblit, actually makes the compiler emit a postblit function: https://d.godbolt.org/#g:!((g:!((g:!((h:codeEditor,i:(j:1,lang:___d,source:'struct+S+%7B%0A++++int+i%3B%0A%0A++++@disable+this(this)%3B%0A%7D'),l:'5',n:'0',o:'D+source+%231',t:'0')),k:34.254797922596914,l:'4',m:100,n:'0',o:'',s:0,t:'0'),(g:!((h:compiler,i:(compiler:ldc180,filters:(b:'0',binary:'1',commentOnly:'0',demangle:'0',directives:'0',execute:'1',intel:'0',trim:'0'),lang:___d,libs:!(),options:'-O3',source:1,wantOptInfo:'1'),l:'5',n:'0',o:'ldc+1.8.0+(Editor+%231,+Compiler+%231)+D',t:'0')),k:32.41186874406977,l:'4',m:100,n:'0',o:'',s:0,t:'0'),(g:!((h:compiler,i:(compiler:dmd20790,filters:(b:'0',binary:'1',commentOnly:'0',demangle:'0',directives:'0',execute:'1',intel:'0',trim:'0'),lang:___d,libs:!(),options:'-O',source:1),l:'5',n:'0',o:'dmd+2.079.0+(Editor+%231,+Compiler+%232)+D',t:'0')),k:33.33333333333333,l:'4',n:'0',o:'',s:0,t:'0')),l:'2',n:'0',o:'',t:'0')),version:4
Comment #6 by johanengelen — 2018-03-20T23:36:10Z
(In reply to johanengelen from comment #5) > > Currently, adding `@disable this(this)` to a struct that normally wouldn't > have a postblit, actually makes the compiler emit a postblit function Interestingly without @disable, no postblit is emitted when just a declaration is given: ``` struct S { int i; @disable this(this); // will emit S.__aggrPostblit() function } ``` without @disable: ``` struct S { int i; this(this); // will _not_ emit S.__aggrPostblit() function } ```
Comment #7 by robert.schadek — 2024-12-13T18:57:55Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/17852 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB