Thread overview
[Issue 4995] invariant() can violate a function's nothrow
Jun 02, 2014
Walter Bright
Dec 08, 2021
Stanislav Blinov
Dec 08, 2021
Stanislav Blinov
Dec 17, 2022
Iain Buclaw
June 02, 2014
https://issues.dlang.org/show_bug.cgi?id=4995

Walter Bright <bugzilla@digitalmars.com> changed:

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

--- Comment #2 from Walter Bright <bugzilla@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.

--
December 08, 2021
https://issues.dlang.org/show_bug.cgi?id=4995

Stanislav Blinov <stanislav.blinov@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           See Also|                            |https://issues.dlang.org/sh
                   |                            |ow_bug.cgi?id=13118

--
December 08, 2021
https://issues.dlang.org/show_bug.cgi?id=4995

Stanislav Blinov <stanislav.blinov@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           See Also|                            |https://issues.dlang.org/sh
                   |                            |ow_bug.cgi?id=18494

--
December 17, 2022
https://issues.dlang.org/show_bug.cgi?id=4995

Iain Buclaw <ibuclaw@gdcproject.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P2                          |P3

--