www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 21210] New: std.traits : isAssignable false positive on

https://issues.dlang.org/show_bug.cgi?id=21210

          Issue ID: 21210
           Summary: std.traits : isAssignable false positive on disabled
                    copy struct
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P1
         Component: phobos
          Assignee: nobody puremagic.com
          Reporter: pro.mathias.lang gmail.com

The following code should either compile, or trigger the static assert:
```
import std.traits;

struct NC {  disable this(this); }

void main ()
{
    NC a, c;
    static assert(isAssignable!NC);
    c = NC();
    c = a;
}
```

Because `isAssignable` definition checks that both lvalues and rvalues can be
used.
However, on the lvalue assignment (`c = a`), the compiler errors out, even
though the `static assert` passed.

Found after https://github.com/dlang/phobos/pull/7609 was reverted.
I believe the reason for this is some aggressive const-folding on the compiler
side.

--
Aug 30 2020