www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 12645] New: assertThrown!Error and assertNotThrown!Error

https://issues.dlang.org/show_bug.cgi?id=12645

          Issue ID: 12645
           Summary: assertThrown!Error and assertNotThrown!Error should be
                    nothrow
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P1
         Component: Phobos
          Assignee: andrej.mitrovich gmail.com
          Reporter: andrej.mitrovich gmail.com

-----
import std.exception;

void main() nothrow
{
    // should be marked nothrow
    assertThrown!Error( { throw new Error(""); }() );

    // ditto
    assertNotThrown!Error( { }() );
}
-----

test.d(8): Error: 'std.exception.assertThrown!(Error, void).assertThrown' is
not nothrow
test.d(11): Error: 'std.exception.assertNotThrown!(Error,
void).assertNotThrown' is not nothrow
test.d(5): Error: function 'D main' is nothrow yet may throw

The way to handle this is to make these two templates wrap function templates
inside, and use a static if section to mark one of the code paths as nothrow.

--
Apr 25 2014