From 0339b6acdeb74ff28cfa2ec30ec5a192709e8695 Mon Sep 17 00:00:00 2001 From: Shin Fujishiro Date: Thu, 18 Nov 2010 21:26:03 +0000 Subject: [PATCH] Made std.exception.pointsTo "@trusted pure nothrow". Also made it tolerant of shared objects. It's @trusted to cast shared away because the function just compares the addresses of passed objects. --- std/exception.d | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/std/exception.d b/std/exception.d index ff1c770a1..8f5eb0410 100644 --- a/std/exception.d +++ b/std/exception.d @@ -361,11 +361,12 @@ that points to $(D target)'s representation or somewhere inside it. Note that evaluating $(D pointsTo(x, x)) checks whether $(D x) has internal pointers. */ -bool pointsTo(S, T)(ref S source, ref T target) +bool pointsTo(S, T)(ref const S source, ref const T target) @trusted pure nothrow { static if (is(S P : U*, U)) { - const void * m = source, b = &target, e = b + target.sizeof; + const m = cast(void*) source, + b = cast(void*) &target, e = b + target.sizeof; return b <= m && m < e; } else static if (is(S == struct)) @@ -379,8 +380,8 @@ bool pointsTo(S, T)(ref S source, ref T target) } else static if (isDynamicArray!(S)) { - const void* p1 = source.ptr, p2 = p1 + source.length, - b = &target, e = b + target.sizeof; + const p1 = cast(void*) source.ptr, p2 = p1 + source.length, + b = cast(void*) &target, e = b + target.sizeof; return overlap(p1[0 .. p2 - p1], b[0 .. e - b]).length != 0; } else @@ -421,6 +422,10 @@ unittest Holder h; pointsTo(h, h); } + + shared S3 sh3; + shared sh3sub = sh3.a[]; + assert(pointsTo(sh3sub, sh3)); } /*********************