Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix 21210: std.traits : isAssignable false positive on disabled copy struct #7612

Merged
merged 1 commit into from
Aug 31, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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; });
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this a more of a workaround for a compiler issue?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm conflicted about this, because I'm not exactly sure of what code path is taken within the compiler.
However, I can see why this behavior (CTFE-ing the expression) would make sense. But it's also a fatal flaw with __traits(compiles, ...), which is not shared by is(typeof(...)). On a related not, I never understood why we added the former if we had the latter.


// 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