This code should work, but doesn't.
void assertThrown(E)(lazy E expression)
{
expression();
}
void main() nothrow
{
assertThrown( 0 );
}
Currently lazy parameter evaluation `epxression()` is treated as @safe and pure, but does not marked as nothrow. It's a bug.
*** Issue 12664 has been marked as a duplicate of this issue. ***
Comment #4 by pro.mathias.lang — 2015-02-17T06:57:25Z
*** Issue 7267 has been marked as a duplicate of this issue. ***
Comment #5 by per.nordlow — 2016-07-06T13:25:22Z
If this gets fixed the bug comment at
file:///home/per/ware/dlang_org/web/phobos-prerelease/std_algorithm_comparison.html#.either
should be removed.
Comment #6 by greeenify — 2016-12-23T06:01:08Z
This a really annoying limitation during the process of annotating Phobos unittests.
It leads from a nice one-liner, e.g.
assertThrown!AssertError(arr.stride(0));
to be replaced with 10 lines:
bool passed = false;
scope (success) assert(passed);
try
{
cast(void) arr.stride(0);
}
catch (AssertError unused)
{
passed = true;
}