Skip to content

Commit

Permalink
Fix 21210: std.traits : isAssignable false positive on disabled copy …
Browse files Browse the repository at this point in the history
…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).
  • Loading branch information
Geod24 authored and dlang-bot committed Aug 31, 2020
1 parent 46f590b commit 4d01cac
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions std/traits.d
Original file line number Diff line number Diff line change
Expand Up @@ -5180,10 +5180,10 @@ enum isAssignable(Lhs, Rhs = Lhs) = isRvalueAssignable!(Lhs, Rhs) && isLvalueAss
}

// ditto
private enum isRvalueAssignable(Lhs, Rhs = Lhs) = __traits(compiles, lvalueOf!Lhs = rvalueOf!Rhs);
private enum isRvalueAssignable(Lhs, Rhs = Lhs) = __traits(compiles, { lvalueOf!Lhs = rvalueOf!Rhs; });

// ditto
private enum isLvalueAssignable(Lhs, Rhs = Lhs) = __traits(compiles, lvalueOf!Lhs = lvalueOf!Rhs);
private enum isLvalueAssignable(Lhs, Rhs = Lhs) = __traits(compiles, { lvalueOf!Lhs = lvalueOf!Rhs; });

@safe unittest
{
Expand Down Expand Up @@ -5224,6 +5224,9 @@ private enum isLvalueAssignable(Lhs, Rhs = Lhs) = __traits(compiles, lvalueOf!Lh
static assert(!isRvalueAssignable!(S6, S5));
static assert( isLvalueAssignable!(S6, S5));
static assert( isLvalueAssignable!(S6, immutable S5));

// https://issues.dlang.org/show_bug.cgi?id=21210
static assert(!isAssignable!S5);
}


Expand Down

0 comments on commit 4d01cac

Please sign in to comment.