Fix for issue# 8398.

This commit is contained in:
jmdavis 2012-07-22 00:40:25 -07:00
parent 87a143e4a8
commit ed22f41ec2

View file

@ -488,7 +488,9 @@ T errnoEnforce(T, string file = __FILE__, size_t line = __LINE__)
/++ /++
If $(D !!value) is $(D true), $(D value) is returned. Otherwise, If $(D !!value) is $(D true), $(D value) is returned. Otherwise,
$(D new E(msg, file, line)) is thrown. $(D new E(msg, file, line)) is thrown. Or if $(D E) doesn't take a message
and can be constructed with $(D new E(file, line)), then
$(D new E(file, line)) will be thrown.
Example: Example:
-------------------- --------------------
@ -507,6 +509,16 @@ template enforceEx(E)
} }
} }
template enforceEx(E)
if (is(typeof(new E(__FILE__, __LINE__))) && !is(typeof(new E("", __FILE__, __LINE__))))
{
T enforceEx(T)(T value, string file = __FILE__, size_t line = __LINE__) @safe pure
{
if (!value) throw new E(file, line);
return value;
}
}
/++ /++
$(RED Deprecated. It will be removed in October 2012. Please use the version $(RED Deprecated. It will be removed in October 2012. Please use the version
of $(D enforceEx) which takes an exception that constructs with of $(D enforceEx) which takes an exception that constructs with
@ -516,7 +528,7 @@ template enforceEx(E)
$(D new E(msg)) is thrown. $(D new E(msg)) is thrown.
+/ +/
deprecated template enforceEx(E) deprecated template enforceEx(E)
if (is(typeof(new E(""))) && !is(typeof(new E("", __FILE__, __LINE__)))) if (is(typeof(new E(""))) && !is(typeof(new E("", __FILE__, __LINE__))) && !is(typeof(new E(__FILE__, __LINE__))))
{ {
T enforceEx(T)(T value, lazy string msg = "") @safe pure T enforceEx(T)(T value, lazy string msg = "") @safe pure
{ {
@ -529,6 +541,7 @@ unittest
{ {
assertNotThrown(enforceEx!Exception(true)); assertNotThrown(enforceEx!Exception(true));
assertNotThrown(enforceEx!Exception(true, "blah")); assertNotThrown(enforceEx!Exception(true, "blah"));
assertNotThrown(enforceEx!OutOfMemoryError(true));
{ {
auto e = collectException(enforceEx!Exception(false)); auto e = collectException(enforceEx!Exception(false));