Skip to content

Commit

Permalink
Merge pull request #2472 from monarchdodra/doesPointToReg
Browse files Browse the repository at this point in the history
Use reinterpret cast is [does|may]PointTo
  • Loading branch information
H. S. Teoh committed Sep 4, 2014
2 parents dea935d + fa10a4e commit a519789
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions std/exception.d
Expand Up @@ -983,8 +983,9 @@ bool doesPointTo(S, T, Tdummy=void)(auto ref const S source, ref const T target)
{
static if (isPointer!S || is(S == class) || is(S == interface))
{
const m = cast(void*) source,
b = cast(void*) &target, e = b + target.sizeof;
const m = *cast(void**) &source;
const b = cast(void*) ⌖
const e = b + target.sizeof;
return b <= m && m < e;
}
else static if (is(S == struct) || is(S == union))
Expand Down Expand Up @@ -1016,8 +1017,9 @@ bool mayPointTo(S, T, Tdummy=void)(auto ref const S source, ref const T target)
{
static if (isPointer!S || is(S == class) || is(S == interface))
{
const m = cast(void*) source,
b = cast(void*) &target, e = b + target.sizeof;
const m = *cast(void**) &source;
const b = cast(void*) &target;
const e = b + target.sizeof;
return b <= m && m < e;
}
else static if (is(S == struct) || is(S == union))
Expand Down Expand Up @@ -1366,6 +1368,21 @@ unittest //alias this test
assert( doesPointTo(cast(int*)s, i));
assert(!doesPointTo(cast(int*)s, j));
}
unittest //more alias this opCast
{
void* p;
class 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));
}

/*********************
* Thrown if errors that set $(D errno) occur.
Expand Down

0 comments on commit a519789

Please sign in to comment.