digitalmars.D.bugs - [Issue 18946] New: assert message can throw hijacking the assert
- d-bugmail puremagic.com (37/37) Jun 05 2018 https://issues.dlang.org/show_bug.cgi?id=18946
https://issues.dlang.org/show_bug.cgi?id=18946 Issue ID: 18946 Summary: assert message can throw hijacking the assert failure. Product: D Version: D2 Hardware: x86 OS: Mac OS X Status: NEW Severity: enhancement Priority: P1 Component: dmd Assignee: nobody puremagic.com Reporter: iamthewilsonator hotmail.com from https://forum.dlang.org/thread/pf5gm7$14gb$1 digitalmars.com import std.stdio; import core.exception; // mess with the compiler's reasoning about the truthiness // of the assert, otherwise the trailing catches are removed // as dead code, triggering the implicit one around Dmain bool returnsFalse() { return false;} void main() { try { static string throwingFunc() { throw new Exception("An exception"); } assert(returnsFalse(), throwingFunc()); } catch(Exception ex) { writeln("Exception"); } catch(AssertError ex) { writeln("Assert"); } } prints Exception the compiler should be at least warn that the message expression is not nothrow. but we should probably deprecate it. --
Jun 05 2018