Fix recent isPointer changes to use is(T == U*, U) instead of is(T : U*, U)

The behaviors are different and the changes appear accidental rather
than deliberate. In at least one case the change would result in wrong
behavior:

https://github.com/dlang/phobos/pull/8635#issuecomment-1433898162

Affected PRs: #8635, #8636, #8637, #8638, #8639
This commit is contained in:
Nathan Sashihara 2023-02-16 19:15:05 -05:00
parent 3acf18c099
commit 68c7ec8d25
5 changed files with 9 additions and 24 deletions

View file

@ -1069,9 +1069,9 @@ as the language is free to assume objects don't have internal pointers
*/
bool doesPointTo(S, T, Tdummy=void)(auto ref const S source, ref const T target) @nogc @trusted pure nothrow
if (__traits(isRef, source) || isDynamicArray!S ||
is(S : U*, U) || is(S == class))
is(S == U*, U) || is(S == class))
{
static if (is(S : U*, U) || is(S == class) || is(S == interface))
static if (is(S == U*, U) || is(S == class) || is(S == interface))
{
const m = *cast(void**) &source;
const b = cast(void*) ⌖
@ -1115,9 +1115,9 @@ bool doesPointTo(S, T)(auto ref const shared S source, ref const shared T target
/// ditto
bool mayPointTo(S, T, Tdummy=void)(auto ref const S source, ref const T target) @trusted pure nothrow
if (__traits(isRef, source) || isDynamicArray!S ||
is(S : U*, U) || is(S == class))
is(S == U*, U) || is(S == class))
{
static if (is(S : U*, U) || is(S == class) || is(S == interface))
static if (is(S == U*, U) || is(S == class) || is(S == interface))
{
const m = *cast(void**) &source;
const b = cast(void*) ⌖
@ -1533,21 +1533,6 @@ version (StdUnittest)
assert( doesPointTo(cast(int*) s, i));
assert(!doesPointTo(cast(int*) s, j));
}
@safe unittest //more alias this opCast
{
void* p;
struct A
{
void* opCast(T)() if (is(T == void*))
{
return p;
}
alias foo = opCast!(void*);
alias foo this;
}
assert(!doesPointTo(A.init, p));
assert(!mayPointTo(A.init, p));
}
/+
Returns true if the field at index `i` in ($D T) shares its address with another field.