Thread overview
[Issue 18628] @disable this(this) erroneously adds `__postblit` member
Mar 19, 2018
RazvanN
Mar 19, 2018
RazvanN
Dec 17, 2022
Iain Buclaw
March 18, 2018
https://issues.dlang.org/show_bug.cgi?id=18628

johanengelen@weka.io changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |industry

--
March 19, 2018
https://issues.dlang.org/show_bug.cgi?id=18628

RazvanN <razvan.nitu1305@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |razvan.nitu1305@gmail.com

--- Comment #1 from RazvanN <razvan.nitu1305@gmail.com> ---
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

--
March 19, 2018
https://issues.dlang.org/show_bug.cgi?id=18628

--- Comment #2 from RazvanN <razvan.nitu1305@gmail.com> ---
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.

--
March 19, 2018
https://issues.dlang.org/show_bug.cgi?id=18628

Andrei Alexandrescu <andrei@erdani.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |andrei@erdani.com

--- Comment #3 from Andrei Alexandrescu <andrei@erdani.com> ---
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.

--
March 19, 2018
https://issues.dlang.org/show_bug.cgi?id=18628

--- Comment #4 from Andrei Alexandrescu <andrei@erdani.com> ---
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.

--
March 20, 2018
https://issues.dlang.org/show_bug.cgi?id=18628

--- Comment #5 from johanengelen@weka.io ---
(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

--
March 20, 2018
https://issues.dlang.org/show_bug.cgi?id=18628

--- Comment #6 from johanengelen@weka.io ---
(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
}
```

--
December 17, 2022
https://issues.dlang.org/show_bug.cgi?id=18628

Iain Buclaw <ibuclaw@gdcproject.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P1                          |P3

--