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

@ -170,7 +170,7 @@ if (isIterable!Range && !isAutodecodableString!Range && !isInfinite!Range)
/// ditto /// ditto
ForeachType!(typeof((*Range).init))[] array(Range)(Range r) ForeachType!(typeof((*Range).init))[] array(Range)(Range r)
if (is(Range : U*, U) && isIterable!U && !isAutodecodableString!Range && !isInfinite!Range) if (is(Range == U*, U) && isIterable!U && !isAutodecodableString!Range && !isInfinite!Range)
{ {
return array(*r); return array(*r);
} }

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 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 || 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 m = *cast(void**) &source;
const b = cast(void*) ⌖ const b = cast(void*) ⌖
@ -1115,9 +1115,9 @@ bool doesPointTo(S, T)(auto ref const shared S source, ref const shared T target
/// ditto /// ditto
bool mayPointTo(S, T, Tdummy=void)(auto ref const S source, ref const T target) @trusted pure nothrow bool mayPointTo(S, T, Tdummy=void)(auto ref const S source, ref const T target) @trusted pure nothrow
if (__traits(isRef, source) || isDynamicArray!S || 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 m = *cast(void**) &source;
const b = cast(void*) ⌖ const b = cast(void*) ⌖
@ -1533,21 +1533,6 @@ version (StdUnittest)
assert( doesPointTo(cast(int*) s, i)); assert( doesPointTo(cast(int*) s, i));
assert(!doesPointTo(cast(int*) s, j)); 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. Returns true if the field at index `i` in ($D T) shares its address with another field.

View file

@ -558,7 +558,7 @@ private template optionValidator(A...)
import std.format : format; import std.format : format;
enum fmt = "getopt validator: %s (at position %d)"; enum fmt = "getopt validator: %s (at position %d)";
enum isReceiver(T) = is(T : U*, U) || (is(T == function)) || (is(T == delegate)); enum isReceiver(T) = is(T == U*, U) || (is(T == function)) || (is(T == delegate));
enum isOptionStr(T) = isSomeString!T || isSomeChar!T; enum isOptionStr(T) = isSomeString!T || isSomeChar!T;
auto validator() auto validator()

View file

@ -889,7 +889,7 @@ private template fqnType(T,
); );
} }
} }
else static if (is(T : U*, U)) else static if (is(T == U*, U))
{ {
enum fqnType = chain!( enum fqnType = chain!(
fqnType!(U, qualifiers) ~ "*" fqnType!(U, qualifiers) ~ "*"
@ -3925,7 +3925,7 @@ template hasStaticMember(T, string member)
{ {
static if (__traits(hasMember, T, member)) static if (__traits(hasMember, T, member))
{ {
static if (is(T : V*, V)) static if (is(T == V*, V))
alias U = V; alias U = V;
else else
alias U = T; alias U = T;

View file

@ -3136,7 +3136,7 @@ private T toUTFImpl(T, S)(scope S s)
collection cycle and cause a nasty bug when the C code tries to use it. collection cycle and cause a nasty bug when the C code tries to use it.
+/ +/
template toUTFz(P) template toUTFz(P)
if (is(P : C*, C) && isSomeChar!C) if (is(P == C*, C) && isSomeChar!C)
{ {
P toUTFz(S)(S str) @safe pure P toUTFz(S)(S str) @safe pure
if (isSomeString!S) if (isSomeString!S)