From 35fa2d9392527db4a08966652eaec90352a9614b Mon Sep 17 00:00:00 2001 From: Sebastian Wilzbach Date: Fri, 15 Dec 2017 15:51:39 +0100 Subject: [PATCH] Fix Issue 18024 - checkedint.Warn should be @safe --- std/experimental/checkedint.d | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/std/experimental/checkedint.d b/std/experimental/checkedint.d index c07566ee6d3..bb35475c832 100644 --- a/std/experimental/checkedint.d +++ b/std/experimental/checkedint.d @@ -194,7 +194,7 @@ module std.experimental.checkedint; import std.traits : isFloatingPoint, isIntegral, isNumeric, isUnsigned, Unqual; /// -@system unittest +@safe unittest { int[] concatAndAdd(int[] a, int[] b, int offset) { @@ -996,7 +996,7 @@ if (is(typeof(Checked!(T, Hook)(value)))) } /// -@system unittest +@safe unittest { static assert(is(typeof(checked(42)) == Checked!int)); assert(checked(42) == Checked!int(42)); @@ -1159,7 +1159,7 @@ static: } } -@system unittest +@safe unittest { void test(T)() { @@ -1368,8 +1368,13 @@ default behavior. */ struct Warn { - import std.stdio : stderr; + import std.stdio : File; static: + private @property File trustedStderr() @trusted + { + import std.stdio : stderr; + return stderr; + } /** Called automatically upon a bad cast from `src` to type `Dst` (one that @@ -1385,7 +1390,7 @@ static: */ Dst onBadCast(Dst, Src)(Src src) { - stderr.writefln("Erroneous cast: cast(%s) %s(%s)", + trustedStderr.writefln("Erroneous cast: cast(%s) %s(%s)", Dst.stringof, Src.stringof, src); return cast(Dst) src; } @@ -1404,14 +1409,14 @@ static: */ Lhs onLowerBound(Rhs, T)(Rhs rhs, T bound) { - stderr.writefln("Lower bound error: %s(%s) < %s(%s)", + trustedStderr.writefln("Lower bound error: %s(%s) < %s(%s)", Rhs.stringof, rhs, T.stringof, bound); return cast(T) rhs; } /// ditto T onUpperBound(Rhs, T)(Rhs rhs, T bound) { - stderr.writefln("Upper bound error: %s(%s) > %s(%s)", + trustedStderr.writefln("Upper bound error: %s(%s) > %s(%s)", Rhs.stringof, rhs, T.stringof, bound); return cast(T) rhs; } @@ -1438,7 +1443,7 @@ static: auto result = opChecked!"=="(lhs, rhs, error); if (error) { - stderr.writefln("Erroneous comparison: %s(%s) == %s(%s)", + trustedStderr.writefln("Erroneous comparison: %s(%s) == %s(%s)", Lhs.stringof, lhs, Rhs.stringof, rhs); return lhs == rhs; } @@ -1477,7 +1482,7 @@ static: auto result = opChecked!"cmp"(lhs, rhs, error); if (error) { - stderr.writefln("Erroneous ordering comparison: %s(%s) and %s(%s)", + trustedStderr.writefln("Erroneous ordering comparison: %s(%s) and %s(%s)", Lhs.stringof, lhs, Rhs.stringof, rhs); return lhs < rhs ? -1 : lhs > rhs; } @@ -1510,21 +1515,21 @@ static: */ typeof(~Lhs()) onOverflow(string x, Lhs)(ref Lhs lhs) { - stderr.writefln("Overflow on unary operator: %s%s(%s)", + trustedStderr.writefln("Overflow on unary operator: %s%s(%s)", x, Lhs.stringof, lhs); return mixin(x ~ "lhs"); } /// ditto typeof(Lhs() + Rhs()) onOverflow(string x, Lhs, Rhs)(Lhs lhs, Rhs rhs) { - stderr.writefln("Overflow on binary operator: %s(%s) %s %s(%s)", + trustedStderr.writefln("Overflow on binary operator: %s(%s) %s %s(%s)", Lhs.stringof, lhs, x, Rhs.stringof, rhs); return mixin("lhs" ~ x ~ "rhs"); } } /// -@system unittest +@safe unittest { auto x = checked!Warn(42); short x1 = cast(short) x;