Request for Comment assert(__ctfe)

Jacob Carlborg doob at me.com
Wed Apr 8 18:48:49 UTC 2020


On 2020-04-07 21:33, tsbockman wrote:

> Catching an AssertError thrown by an assert statement is officially 
> undefined behavior:
> https://dlang.org/spec/expression.html#assert_expressions

Ok, let me tweak the example a bit:

void foo()
{
     assert(__ctfe);
}

unittest @system
{
     try
         foo();
     catch (AssertError)
     {}
}

Then if you read the third item in the list:

"AssertExpression has different semantics if it is in a unittest or in 
contract."

Then you read the unittest spec [1], the third item, the second sentence:

"Unlike AssertExpressions used elsewhere, the assert is not assumed to 
hold, and upon assert failure the program is still in a defined state."

Now it's not undefined anymore.

[1] https://dlang.org/spec/unittest.html

-- 
/Jacob Carlborg


More information about the Digitalmars-d mailing list