[Issue 4995] invariant() can violate a function's nothrow

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Sun Jun 1 13:46:04 PDT 2014


https://issues.dlang.org/show_bug.cgi?id=4995

Walter Bright <bugzilla at digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bugzilla at digitalmars.com

--- Comment #2 from Walter Bright <bugzilla at digitalmars.com> ---
(In reply to Henning Pohl from comment #1)
> https://github.com/D-Programming-Language/dmd/pull/2155

This PR has a number of possible approaches. The difficulty is there are a
number of attributes:

    nothrow, @safe, pure, @nogc, const, immutable, shared

that may apply to invariants. Currently, const is applied. The PR applies pure
(but does not check it) and @trusted, and adds code to silently convert thrown
Exceptions to Errors inside of nothrow functions.

I'm uneasy with this. We also have backwards compatibility to be concerned
about.

1. I can't think of a legitimate case where invariant can throw an Exception.
Calling invariants or not should not be altering the normal behavior of a
program. Hence, invariant should be implicitly nothrow.

2. Removal of checks for @system and purity is a hidden escape from the static
guarantees of the language - seems wrong to me.

3. I think we can require the existence of a function body for invariants, and
then do attribute inference on it.

--


More information about the Digitalmars-d-bugs mailing list