D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 21210 - std.traits : isAssignable false positive on disabled copy struct
Summary: std.traits : isAssignable false positive on disabled copy struct
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: phobos (show other issues)
Version: D2
Hardware: All All
: P1 normal
Assignee: No Owner
URL:
Keywords: pull
Depends on:
Blocks:
 
Reported: 2020-08-30 14:01 UTC by Mathias LANG
Modified: 2020-08-31 01:14 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Mathias LANG 2020-08-30 14:01:45 UTC
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.
Comment 1 Dlang Bot 2020-08-30 18:05:26 UTC
@Geod24 created dlang/phobos pull request #7612 "Fix 21210:  std.traits : isAssignable false positive on disabled copy struct" fixing this issue:

- Fix 21210:  std.traits : isAssignable false positive on disabled copy struct
  
  `isAssignable` would previously return `true` for non-copyable types,
  even though code that tried to use an lvalue would not compile.
  This behavior was originally found when implementing `-preview=in`.
  
  With the new -preview=in check, the const-folding seemed to be a bit
  too aggressive when an rvalue is passed, meaning that the check might
  fail (probably due to the code that initialize the temporary).

https://github.com/dlang/phobos/pull/7612
Comment 2 Dlang Bot 2020-08-31 01:14:02 UTC
dlang/phobos pull request #7612 "Fix 21210:  std.traits : isAssignable false positive on disabled copy struct" was merged into master:

- f6bf36d155a2749e31b32641d9f11bf34e3c1c43 by Geod24:
  Fix 21210:  std.traits : isAssignable false positive on disabled copy struct
  
  `isAssignable` would previously return `true` for non-copyable types,
  even though code that tried to use an lvalue would not compile.
  This behavior was originally found when implementing `-preview=in`.
  
  With the new -preview=in check, the const-folding seemed to be a bit
  too aggressive when an rvalue is passed, meaning that the check might
  fail (probably due to the code that initialize the temporary).

https://github.com/dlang/phobos/pull/7612