[Issue 19793] no postblit is called if cast is used for structs
    d-bugmail at puremagic.com 
    d-bugmail at puremagic.com
       
    Tue Apr  9 08:11:54 UTC 2019
    
    
  
https://issues.dlang.org/show_bug.cgi?id=19793
RazvanN <razvan.nitu1305 at gmail.com> changed:
           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |razvan.nitu1305 at gmail.com
--- Comment #3 from RazvanN <razvan.nitu1305 at gmail.com> ---
(In reply to Илья Ярошенко from comment #0)
> struct S(T)
> {
>     size_t* counter;
> 
>     this(this)
>     {
>         if (counter)
>             ++counter[0];
>     }
> 
>     ~this()
>     {
>         if (counter)
>             --counter[0];
>     }
>     
>     static S create()
>     {
>         return S(new size_t(1));
>     }
> }
> 
> auto constOf(S!int a)
> {
>     return cast(S!(const int)) a;
> }
> 
> void main()
> {
> 	auto s = S!int.create;
>     assert(s.counter[0] == 1); // pass
>     auto a = constOf(s);
>     assert(s.counter[0] == 2); // fails
> }
Up untile recently, casts were considered rvalues in dmd while postblits get
called solely on lvalues. However this was recently changed in the specs [1] so
that `cast()` and `cast(qualifier)` are lvalues. A PR was submitted to get the
implementation in sync with the spec [2], so I suspect that that will also fix
this issue.
[1] https://github.com/dlang/dlang.org/pull/2606
[2] https://github.com/dlang/dmd/pull/9505
--
    
    
More information about the Digitalmars-d-bugs
mailing list