[Issue 18946] New: assert message can throw hijacking the assert failure.

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Jun 5 12:45:35 UTC 2018


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 at puremagic.com
          Reporter: iamthewilsonator at 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.

--


More information about the Digitalmars-d-bugs mailing list