Bug 21210 – std.traits : isAssignable false positive on disabled copy struct

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2020-08-30T14:01:45Z
Last change time
2020-08-31T01:14:02Z
Keywords
pull
Assigned to
No Owner
Creator
Mathias LANG

Comments

Comment #0 by pro.mathias.lang — 2020-08-30T14:01:45Z
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 by dlang-bot — 2020-08-30T18:05:26Z
@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 by dlang-bot — 2020-08-31T01:14:02Z
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