Copy constructors and IsExpression
Stanislav Blinov
stanislav.blinov at gmail.com
Mon Jun 1 15:48:21 UTC 2020
https://dlang.org/spec/expression.html#is_expression
...specifically, the second form, i.e. `is(Type :
TypeSpecialization)`: "The condition is satisfied if Type is
semantically correct and it is the same as or can be implicitly
converted to TypeSpecialization".
Copy constructors expand the realm of implicit conversions, yet
the IsExpression doesn't seem to consider them:
---
struct S {
int* ptr; // note the pointer
this(ref scope const S) { /* ... */ }
}
S copy(ref const S s) { return s; } // OK
void takesMutable(S s) {}
void givesConst() {
const S s;
takesMutable(s); // OK
}
static assert(is(const(S) : S)); // Asserts
---
Was the implementation intentionally not amended to allow for
copy constructors, or was this an oversight? It does, after all,
accept conversions provided by the `alias this`, so why not copy
ctors?
There are a few areas of the language and libraries, including
druntime, that are ignoring copy constructors (for example,
arrays). Is this also one of those?
On another note, is there really no way of recovering password
here? I keep forgetting it on a regular basis.
More information about the Digitalmars-d
mailing list