Bug 18946 – assert message can throw hijacking the assert failure.

Status
RESOLVED
Resolution
WONTFIX
Severity
major
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2018-06-05T12:45:35Z
Last change time
2021-12-06T07:53:18Z
Keywords
safe
Assigned to
No Owner
Creator
Nicholas Wilson

Comments

Comment #0 by iamthewilsonator — 2018-06-05T12:45:35Z
from https://forum.dlang.org/thread/[email protected] 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.
Comment #1 by iamthewilsonator — 2018-09-06T09:05:39Z
https://github.com/dlang/dmd/pull/8673 Upping the priority since this can prevent asserts from doing their thing.
Comment #2 by razvan.nitu1305 — 2021-12-06T07:53:18Z
I don't think this is a valid issue. This is a niche case (where the formatting function throws) and uglifying the compiler to support this is not worth it. Also, the Error should not be caught anyway. If the formatting function throws, it should be the users job to catch this.