www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 18946] New: assert message can throw hijacking the assert


          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) {
    } catch(AssertError ex) {



the compiler should be at least warn that the message expression is not
nothrow. but we should probably deprecate it.

Jun 05 2018