• A better experimental::scope_exit

    From Bonita Montero@3:633/10 to All on Sat Nov 21 18:22:48 2026
    #pragma once
    #include <type_traits>
    #include <cassert>
    #include <utility>
    #include "nui.hpp"

    template<typename Fn, typename Dependent = void>
    struct defer final
    {
    static_assert( std::is_nothrow_invocable_v<Fn> );
    defer( Fn fn, Dependent *pDep = (Dependent *)nullptr ) :
    m_enabled( true ),
    m_fn( std::move( fn ) ),
    m_pDep( pDep )
    {
    assert(std::is_void_v<Dependent> || pDep);
    }
    defer( defer const & ) = delete;
    void operator =( defer const & ) = delete;
    ~defer()
    {
    run();
    }
    void run() noexcept
    {
    constexpr bool DepRunnable = requires { { m_pDep->run() }; };
    static_assert( DepVoid || DepRunnable );
    if( !m_enabled )
    return;
    m_fn();
    m_enabled = false;
    if constexpr( DepRunnable )
    m_pDep->run();
    }
    void disable() noexcept
    {
    constexpr bool DepDisable = requires { { m_pDep->disable() }; };
    static_assert( DepVoid || DepDisable );
    m_enabled = false;
    if constexpr( DepDisable )
    m_pDep->disable();
    }
    private:
    bool m_enabled;
    NO_UNIQUE_ADDRESS Fn m_fn;
    struct empty { empty( void * ) {} };
    static constexpr bool DepVoid = std::is_void_v<Dependent>;
    using dep_t = std::conditional_t<std::is_void_v<Dependent>, empty, Dependent *>;
    NO_UNIQUE_ADDRESS dep_t m_pDep;
    };

    --- PyGate Linux v1.5.19
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From Bonita Montero@3:633/10 to All on Sun Nov 22 18:34:03 2026
    Now it's perfect.

    #pragma once
    #include <type_traits>
    #include <cassert>
    #include <utility>
    #include "nui.hpp"

    template<typename Fn, typename Dependent = void>
    struct defer;

    template<typename Fn, typename Dependent>
    struct defer final
    {
    static_assert( std::is_nothrow_invocable_v<Fn> );
    defer( Fn fn, Dependent *pDep = (Dependent *)nullptr ) :
    m_enabled( true ),
    m_fn( std::move( fn ) ),
    m_pDep( pDep )
    {
    assert(std::is_void_v<Dependent> || pDep);
    }
    defer( defer const & ) = delete;
    void operator =( defer const & ) = delete;
    ~defer()
    {
    run();
    }
    void run() noexcept
    {
    if( !m_enabled )
    return;
    m_fn();
    m_enabled = false;
    if constexpr( !std::is_void_v<Dependent> )
    m_pDep->run();
    }
    void disable() noexcept
    {
    m_enabled = false;
    if constexpr( !std::is_void_v<Dependent> )
    m_pDep->disable();
    }
    private:
    template<typename T>
    struct is_defer : std::false_type {};
    template<typename Fn, typename Dependent>
    struct is_defer<defer<Fn, Dependent>> : std::true_type {};
    static_assert( std::is_void_v<Dependent> || is_defer<Dependent>::value );
    bool m_enabled;
    NO_UNIQUE_ADDRESS Fn m_fn;
    struct empty { empty( void * ) {} };
    static constexpr bool DepVoid = std::is_void_v<Dependent>;
    using dep_t = std::conditional_t<std::is_void_v<Dependent>, empty, Dependent *>;
    NO_UNIQUE_ADDRESS dep_t m_pDep;
    };

    --- PyGate Linux v1.5.19
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From Tristan Wibberley@3:633/10 to All on Mon Nov 23 09:41:52 2026
    On 21/11/2026 17:22, Bonita Montero wrote:
    template<[...]>
    struct defer final
    {
    defer( [...] ) : [...]
    {
    assert(std::is_void_v<Dependent> || pDep);
    }
    On the irregularity of that constraint
    ======================================

    A little excess irregularity, I feel; why not provide a static instance
    of "empty" which can be used to terminate the list of deps then provide
    an explicit template specialisation for the sugar of using "void"?

    Furthermore "assert" is a bit risky because it's /always/ invalid to
    flow the control onward when the condition isn't met, not only in builds
    other than NDEBUG, yet C++ has exceptions to abort and avoid invalid continuation too. Typically even programs compiled for systems without
    catch can throw which can just abort much like a failed assert does on
    those systems. Then, for performance concerns for keeping the test with
    NDEBUG, the constructor is inlineable so the compiler could, in theory,
    elide the test when the client code would never trigger it in a hot loop.


    On the specific dual patterning
    ===============================

    Do you mean it to be dual pattern either:

    a) pointer to instance of any type with the required interface which
    re-implements the necessary member functions
    b) all work provided exactly when the client code has only a function

    I feel there could be some improvement also by making the basic features
    of disablement and forwarding available to derived classes which merely
    then need to override a virtual member function to complete their
    typical implementation. Which brings me to ...


    On final
    ========

    I'm a bit out of date, I suppose "final" prevents derivation, but why
    prevent it? Some need to restrict all "new" instances to some special
    array, perhaps? It would be a bit odd.

    Perhaps you can't allow a vtable or such for this type or you want to
    make sure "delete" can be used on pointers to "defer<what...>" without
    causing a virtual destructor and therefore vtable for each?


    --
    Tristan Wibberley

    The message body is Copyright (C) 2026 Tristan Wibberley except
    citations and quotations noted. All Rights Reserved except that you may,
    of course, cite it academically giving credit to me, distribute it
    verbatim as part of a usenet system or its archives, and use it to
    promote my greatness and general superiority without misrepresentation
    of my opinions other than my opinion of my greatness and general
    superiority which you _may_ misrepresent. You definitely MAY NOT train
    any production AI system with it but you may train experimental AI that
    will only be used for evaluation of the AI methods it implements.

    --- PyGate Linux v1.5.19
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From David Brown@3:633/10 to All on Mon Nov 23 13:26:14 2026
    On 21/11/2026 18:22, Bonita Montero wrote:
    #pragma once
    #include <type_traits>
    #include <cassert>
    #include <utility>
    #include "nui.hpp"

    A dependency on a non-standard header - if your code really is dependent
    on "nui.hpp" - makes your code useless to anyone else.

    Apart from that, what makes you think your version is "better" than the
    the proposed standard version in "experimental::" ?

    Or the C++ "defer" version here?

    <https://gustedt.wordpress.com/2025/01/06/simple-defer-ready-to-use/>

    Or any other simple RAII wrapper like :

    template<typename T>
    struct scope_exit {
    T f;
    scope_exit(T f) : f(f) { }
    ~scope_exit() { f(); }
    };

    or a template on a lambda (like in Gustedt's version) ?

    If you want to claim your solution is "better", start with an example or
    two showing what you can do with your version, that cannot be done with standard or common versions. At the moment, all you have done is shown
    how you can add an apparently pointless "Dependent" function that must
    have a "run" method. And if you are going to require the use of C++20
    for concepts (not a bad idea), then at least use them consistently - put
    the concepts where they belong, restricting the types of the template,
    rather than in static assertions. And drop the C-style "assert" for
    something that is known at compile time.




    template<typename Fn, typename Dependent = void>
    struct defer final
    {
    ÿÿÿÿstatic_assert( std::is_nothrow_invocable_v<Fn> );
    ÿÿÿÿdefer( Fn fn, Dependent *pDep = (Dependent *)nullptr ) :
    ÿÿÿÿÿÿÿ m_enabled( true ),
    ÿÿÿÿÿÿÿ m_fn( std::move( fn ) ),
    ÿÿÿÿÿÿÿ m_pDep( pDep )
    ÿÿÿÿ{
    ÿÿÿÿÿÿÿ assert(std::is_void_v<Dependent> || pDep);
    ÿÿÿÿ}
    ÿÿÿÿdefer( defer const & ) = delete;
    ÿÿÿÿvoid operator =( defer const & ) = delete;
    ÿÿÿÿ~defer()
    ÿÿÿÿ{
    ÿÿÿÿÿÿÿ run();
    ÿÿÿÿ}
    ÿÿÿÿvoid run() noexcept
    ÿÿÿÿ{
    ÿÿÿÿÿÿÿ constexpr bool DepRunnable = requires { { m_pDep->run() }; };
    ÿÿÿÿÿÿÿ static_assert( DepVoid || DepRunnable );
    ÿÿÿÿÿÿÿ if( !m_enabled )
    ÿÿÿÿÿÿÿÿÿÿÿ return;
    ÿÿÿÿÿÿÿ m_fn();
    ÿÿÿÿÿÿÿ m_enabled = false;
    ÿÿÿÿÿÿÿ if constexpr( DepRunnable )
    ÿÿÿÿÿÿÿÿÿÿÿ m_pDep->run();
    ÿÿÿÿ}
    ÿÿÿÿvoid disable() noexcept
    ÿÿÿÿ{
    ÿÿÿÿÿÿÿ constexpr bool DepDisable = requires { { m_pDep->disable() }; };
    ÿÿÿÿÿÿÿ static_assert( DepVoid || DepDisable );
    ÿÿÿÿÿÿÿ m_enabled = false;
    ÿÿÿÿÿÿÿ if constexpr( DepDisable )
    ÿÿÿÿÿÿÿÿÿÿÿ m_pDep->disable();
    ÿÿÿÿ}
    private:
    ÿÿÿÿbool m_enabled;
    ÿÿÿÿNO_UNIQUE_ADDRESS Fn m_fn;
    ÿÿÿÿstruct empty { empty( void * ) {} };
    ÿÿÿÿstatic constexpr bool DepVoid = std::is_void_v<Dependent>;
    ÿÿÿÿusing dep_t = std::conditional_t<std::is_void_v<Dependent>, empty, Dependent *>;
    ÿÿÿÿNO_UNIQUE_ADDRESS dep_t m_pDep;
    };


    --- PyGate Linux v1.5.19
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From Bonita Montero@3:633/10 to All on Mon Nov 23 15:00:22 2026
    Am 23.11.2026 um 13:26 schrieb David Brown:

    template<typename T>
    struct scope_exit {
    ÿÿÿÿT f;
    ÿÿÿÿscope_exit(T f) : f(f) { }
    ÿÿÿÿ~scope_exit() { f(); }
    };

    You can't cascade multiple exits with that. This means if you have
    several manipulations on a data structure and you want to revert them
    if an exception occurs the destructor revers the changes so far. But
    if nothing happens in that sense you simply call .disable() on the
    last node in the chain and all dependent nodes are also disabled.
    Just as a commit in a databse.

    If you want to claim your solution is "better", start with an example or
    two showing what you can do with your version, that cannot be done with standard or common versions.ÿ At the moment, all you have done is shown
    how you can add an apparently pointless "Dependent" function that must
    have a "run" method. ...

    You can see from the code for what the dependent is good for.
    And even more from the static_assert in the private part of the class.

    And if you are going to require the use of C++20 or concepts (not a bad idea), then at least use them consistently - put the concepts where they belong, restricting the types of the template, rather than in static assertions. And drop the C-style "assert" for something that is known
    at compile time.

    I liked concepts until I realized that they make the code less redable
    than the way I did it.

    --- PyGate Linux v1.5.19
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From Bonita Montero@3:633/10 to All on Mon Nov 23 15:07:08 2026
    Am 23.11.2026 um 10:41 schrieb Tristan Wibberley:

    A little excess irregularity, I feel; why not provide a static instance
    of "empty" which can be used to terminate the list of deps then provide
    an explicit template specialisation for the sugar of using "void"?

    The code is correct. If the node our node depends on isn't void

    Furthermore "assert" is a bit risky because it's /always/ invalid to
    flow the control onward when the condition isn't met, not only in builds other than NDEBUG, yet C++ has exceptions to abort and avoid invalid continuation too.

    The code should result in a debug break point and usually the debugger
    doesn't allow any further execution. That's exactly what I want. An
    exception is the wrong thing here.

    Do you mean it to be dual pattern either:
    a) pointer to instance of any type with the required interface which
    re-implements the necessary member functions
    b) all work provided exactly when the client code has only a function

    If you have a disable() on the last node in a chain all nodes we're
    depending on should also be disabled. If you call a run in the same
    manner all nodes we depend on should be executed also.
    Why is that so hard to understand ? It's one screenpage of code.

    I feel there could be some improvement also by making the basic features
    of disablement and forwarding available to derived classes which merely
    then need to override a virtual member function to complete their
    typical implementation. Which brings me to ...

    With virtual functions this woudln't be that lightweight I implemented
    it.

    I'm a bit out of date, I suppose "final" prevents derivation, but why
    prevent it? Some need to restrict all "new" instances to some special
    array, perhaps? It would be a bit odd.

    An extension woudln't make sense. Also because the innards of the class
    are private.


    --- PyGate Linux v1.5.19
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From David Brown@3:633/10 to All on Mon Nov 23 15:19:37 2026
    On 23/11/2026 15:00, Bonita Montero wrote:
    Am 23.11.2026 um 13:26 schrieb David Brown:

    template<typename T>
    struct scope_exit {
    ÿÿÿÿÿT f;
    ÿÿÿÿÿscope_exit(T f) : f(f) { }
    ÿÿÿÿÿ~scope_exit() { f(); }
    };

    You can't cascade multiple exits with that. This means if you have
    several manipulations on a data structure and you want to revert them
    if an exception occurs the destructor revers the changes so far. But
    if nothing happens in that sense you simply call .disable() on the
    last node in the chain and all dependent nodes are also disabled.
    Just as a commit in a databse.


    That is not an example - it's a vague idea of an imagined use-case. Try showing an example, using your scope_exit. Compare it with
    alternatives. Then we will be able to see if and why your code is
    better, and also get an idea whether it would be better to have it in
    addition to normal scope_exit features, rather than instead of them.


    --- PyGate Linux v1.5.19
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From Bonita Montero@3:633/10 to All on Mon Nov 23 15:33:45 2026
    Am 23.11.2026 um 15:19 schrieb David Brown:

    That is not an example - it's a vague idea of an imagined use-case.

    Ususally I don't cascade. But I had this usecase multiple times when
    applying several changes on a data structure where each operation
    could fail with an exception.

    Try showing an example, using your scope_exit.

    Can't you imagine the purpose from the code - poor !

    Compare it with alternatives. ...

    experimental::scope_exit hasn't cascading and no explicit run().

    Then we will be able to see if and why your code is better,
    and also get an idea whether it would be better to have
    it in addition to normal scope_exit features, rather than
    instead of them.

    You really have a lack of imagination.
    Or you don't understand the code.

    --- PyGate Linux v1.5.19
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From David Brown@3:633/10 to All on Mon Nov 23 16:45:47 2026
    On 23/11/2026 15:33, Bonita Montero wrote:
    Am 23.11.2026 um 15:19 schrieb David Brown:

    That is not an example - it's a vague idea of an imagined use-case.

    Ususally I don't cascade. But I had this usecase multiple times when
    applying several changes on a data structure where each operation
    could fail with an exception.

    Tryÿ showing an example, using your scope_exit.

    Can't you imagine the purpose from the code - poor !

    Compare it withÿ alternatives. ...

    experimental::scope_exit hasn't cascading and no explicit run().

    Then we will be able to see if and why your code isÿ better,
    and also get an idea whether it would be better to have it in addition
    to normal scope_exit features, rather than
    instead of them.

    You really have a lack of imagination.
    Or you don't understand the code.

    Programming is not just a matter of churning out lines of code.

    Claiming things are "obvious" or that others "lack imagination" is an
    excuse for being unable or unwilling to explain your own thoughts. If
    you have trouble explaining things, then the suggestions below will
    help. If you are simply unwilling to do so, then why bother posting the
    code in the first place? It is unusable to others as it is, and
    contains nothing particularly innovative. If you are posting it so that
    we can discuss it, then that's great - so discuss it. If not, then why
    did you post it?

    Figure out what you want to achieve. Figure out how the code should be
    used. Specify it, describe it, document it. Show examples. Compare it
    to existing solutions. Show why your "defer" class with "Dependent"
    pointers is necessary, and better than a single "standard" scope_exit
    function that does more than one thing, or multiple "standard"
    scope_exit calls. Explain why it is so common to need theses
    "Dependent" variables that they should be included in a general "defer"
    class, rather than a specialised version used occasionally. Explain why
    a single "Dependent" is enough, rather than accepting multiple
    "Dependents". Explain what you mean by "Dependent" in the first place.


    --- PyGate Linux v1.5.19
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From Bonita Montero@3:633/10 to All on Mon Nov 23 16:54:48 2026
    Am 23.11.2026 um 16:45 schrieb David Brown:

    Claiming things are "obvious" or that others "lack imagination" is
    an excuse for being unable or unwilling to explain your own thoughts.

    It's just one screenpage of code. And the code itself is simpler than
    any real world application. So where's the problem ?

    If you have trouble explaining things, then the suggestions below will
    help.ÿ If you are simply unwilling to do so, then why bother posting
    the code in the first place?ÿ It is unusable to others as it is, and contains nothing particularly innovative.

    Then you still don't understand what I did.


    Figure out what you want to achieve.ÿ Figure out how the code should be used.ÿ Specify it, describe it, document it.ÿ Show examples.ÿ Compare it
    to existing solutions.ÿ Show why your "defer" class with "Dependent" pointers is necessary, and better than a single "standard" scope_exit function that does more than one thing, or multiple "standard"
    scope_exit calls.

    The ide is somewhat unusual, but as the code is very short it's
    not hard to understand.

    Explain why single "Dependent" is enough, rather than accepting multiple "Dependents".ÿ Explain what you mean by "Dependent" in the first place.
    I see: you didn't understand the code.
    The dependents could be cascaded.


    --- PyGate Linux v1.5.19
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From Scott Lurndal@3:633/10 to All on Mon Nov 23 16:37:32 2026
    Bonita Montero <Bonita.Montero@gmail.com> writes:
    Am 23.11.2026 um 13:26 schrieb David Brown:

    template<typename T>
    struct scope_exit {
    ÿÿÿÿT f;
    ÿÿÿÿscope_exit(T f) : f(f) { }
    ÿÿÿÿ~scope_exit() { f(); }
    };

    You can't cascade multiple exits with that. This means if you have
    several manipulations on a data structure and you want to revert them
    if an exception occurs the destructor revers the changes so far. But
    if nothing happens in that sense you simply call .disable() on the
    last node in the chain and all dependent nodes are also disabled.
    Just as a commit in a databse.

    KISS. This is from a 1992-ish port of Unix to run as
    an actor for the Chorus microkernel.

    //
    // Destructor: undo what fork has done upon failure.
    //
    tForkFailure::~tForkFailure()
    {
    if (ret == 0) {
    return;
    }

    if (PActUI != NULL) {
    procp->Mem.Exit(ChildCap);
    }

    //
    // XXXKYS: the DeleteAll() needs to take
    // into account that some of the LWPs
    // in the list may be zombies.
    //
    procp->LwpList.DeleteAll();

    if (rgn == B_TRUE) {
    procp->Rgn.ShmExit(CrLwp, procp);
    }

    if (file == B_TRUE) {
    procp->File.ForkUndo();
    }

    procp->ProcRlim->rlFree(nlwp + 1);
    procp->ProcCred->CrFree(nlwp + 1);

    procp->UidQuota.FreeProc(B_TRUE, total_lwp, 1);
    }

    Aside: The KYS referenced in the comment is now a VP at Microsoft.


    --- PyGate Linux v1.5.19
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From boltar@3:633/10 to All on Mon Nov 23 16:46:34 2026
    On Mon, 23 Nov 2026 16:37:32 GMT
    scott@slp53.sl.home (Scott Lurndal) gabbled:
    Bonita Montero <Bonita.Montero@gmail.com> writes:
    Am 23.11.2026 um 13:26 schrieb David Brown:

    template<typename T>
    struct scope_exit {
    ÿÿÿÿT f;
    ÿÿÿÿscope_exit(T f) : f(f) { }
    ÿÿÿÿ~scope_exit() { f(); }
    };

    You can't cascade multiple exits with that. This means if you have
    several manipulations on a data structure and you want to revert them
    if an exception occurs the destructor revers the changes so far. But
    if nothing happens in that sense you simply call .disable() on the
    last node in the chain and all dependent nodes are also disabled.
    Just as a commit in a databse.

    KISS. This is from a 1992-ish port of Unix to run as
    an actor for the Chorus microkernel.

    //
    // Destructor: undo what fork has done upon failure.
    //
    tForkFailure::~tForkFailure()

    Why is fork failure a specific class? Thats a bit wierd.


    --- PyGate Linux v1.5.19
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From David Brown@3:633/10 to All on Mon Nov 23 17:58:24 2026
    On 23/11/2026 16:54, Bonita Montero wrote:
    Am 23.11.2026 um 16:45 schrieb David Brown:

    Claiming things are "obvious" or that others "lack imagination" is
    an excuse for being unable or unwilling to explain your own thoughts.

    It's just one screenpage of code. And the code itself is simpler than
    any real world application. So where's the problem ?

    If you have trouble explaining things, then the suggestions below will
    help.ÿ If you are simply unwilling to do so, then why bother posting
    theÿ code in the first place?ÿ It is unusable to others as it is, and
    contains nothing particularly innovative.

    Then you still don't understand what I did.


    Figure out what you want to achieve.ÿ Figure out how the code should
    be used.ÿ Specify it, describe it, document it.ÿ Show examples.
    Compare it to existing solutions.ÿ Show why your "defer" class with
    "Dependent" pointers is necessary, and better than a single "standard"
    scope_exit function that does more than one thing, or multiple
    "standard" scope_exit calls.

    The ide is somewhat unusual, but as the code is very short it's
    not hard to understand.

    Explain whyÿ single "Dependent" is enough, rather than accepting
    multiple "Dependents".ÿ Explain what you mean by "Dependent" in the
    first place.
    I see: you didn't understand the code.
    The dependents could be cascaded.


    The code is not the problem. The /purpose/ of the code is the problem.

    Since you apparently cannot or will not give any explanation or usage of
    the code, there is nothing more to be said about it. In the future, I'd recommend you send such pointless code straight to /dev/null and don't
    bother posting anything you are unwilling to talk about.


    --- PyGate Linux v1.5.19
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From Bonita Montero@3:633/10 to All on Mon Nov 23 18:02:43 2026
    Am 23.11.2026 um 17:58 schrieb David Brown:

    Since you apparently cannot or will not give any explanation or
    usage of the code, there is nothing more to be said about it. ...

    I gave an explanation and I said that I use the cascading torevert a
    number of changes on a data structure if the changes
    aren't complete.

    In the future, I'd recommend you send such pointless code straight
    to /dev/null and don't bother posting anything you are unwilling
    to talk about.

    You're a sick nerd.


    --- PyGate Linux v1.5.19
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From Scott Lurndal@3:633/10 to All on Mon Nov 23 17:35:46 2026
    boltar@caprica.universe writes:
    On Mon, 23 Nov 2026 16:37:32 GMT
    scott@slp53.sl.home (Scott Lurndal) gabbled:
    Bonita Montero <Bonita.Montero@gmail.com> writes:
    Am 23.11.2026 um 13:26 schrieb David Brown:

    template<typename T>
    struct scope_exit {
    ÿÿÿÿT f;
    ÿÿÿÿscope_exit(T f) : f(f) { }
    ÿÿÿÿ~scope_exit() { f(); }
    };

    You can't cascade multiple exits with that. This means if you have >>>several manipulations on a data structure and you want to revert them
    if an exception occurs the destructor revers the changes so far. But
    if nothing happens in that sense you simply call .disable() on the
    last node in the chain and all dependent nodes are also disabled.
    Just as a commit in a databse.

    KISS. This is from a 1992-ish port of Unix to run as
    an actor for the Chorus microkernel.

    //
    // Destructor: undo what fork has done upon failure.
    //
    tForkFailure::~tForkFailure()

    Why is fork failure a specific class? Thats a bit wierd.


    Because it is used as a cleanup task to simplify the
    Fork functionality, to wit:

    /
    // int tProc::Fork(KnCap* PActUI, int Caller, tLwp *CrLwp,
    // int IsVFork, boolean_t ForkAll)
    // Perform all the fork time operations for the invoking object.
    //
    // Calling/Exit State:
    // On entry, the LWPs in the parent process other than the forking LWP
    // are at a barrier. Further, the process reader/writer lock of the
    // parent process has been acquired (in the read mode) to keep /proc
    // at bay. The invoking object is fully initialized from the parent
    // process. All the embedded synchronization objects have been initialized.
    //
    // Remarks:
    // The only asynchronous activity in the parent is the result of
    // message handlers executing in the parent.

    int
    tProc::Fork(KnCap* PActUI, int Caller, tLwp *CrLwp, int IsVFork, boolean_t ForkAll)
    {
    int Error = 0;
    int nlwp; // total number of active lwps in the child
    int total_lwp; // total number of lwps in the child (active + zombies)

    ASSERT((Caller == FORK_SYSCALL) || (Caller == FORK_BOOTPROC));

    KnCap *ChildCap = Actor.GetCap();

    // Hand crafted processes do not have a ParentP.
    tProc *ParentP = CrLwp->MyProc();

    // Initialise the global Ops event that is used for global Ops
    // synchronisation

    EVENT_INIT(&GlobalEvt);

    //
    // Only Single threaded processes can vfork().
    // Currently, we don't support vfork.
    if (IsVFork && (!(ParentP->LwpList.SingleThreaded()))) {
    return EINVAL;
    }

    if (ForkAll) {
    nlwp = ParentP->LwpList.GetCountLwp();
    total_lwp = ParentP->LwpList.GetTotalLwp();

    } else {
    nlwp = 1;
    total_lwp = 1;
    }

    //
    // Check to see if we will be exceeding the quota.
    // XXXKYS: Check the interface for picking up quota tokens.
    // Would prefer an interface that accepted the number of
    // tokens needed - proc + lwps.
    // NOTE: The number of LWP tokens picked up will be equal to the
    // total number of LWPs in the child (including zombie LWPs).

    if (UidQuota.Fork(ProcCred->GetUid(), ProcCred->GetEuid(), total_lwp)) {
    return EAGAIN;
    }

    After this point, any resources allocated to the newly created
    process must be deallocated if the fork() fails (e.g. due to
    insufficient resources,

    tForkFailure ff(this, CrLwp, ChildCap, nlwp, total_lwp);

    //
    // Perform fork time operations on the credentials.
    // Basically, apply the necessary holds.
    // NOTE: The UID state we have inherited corresponds to the
    // credential state we have inherited (at the process level).
    // We will synch up all the LWPs in the child to the process
    // level cred state.

    ProcCred->CrHold(nlwp + 1);

    //
    // Perform the fork time operations on the resource limits.
    // Refer to the note under the credential operation above.

    ProcRlim->rlHold(nlwp + 1);

    ...

    //
    // Write an accounting record
    //
    ParentP->Acct.Fork(); // Count another child

    if (SystemAccounting.isEnabled( ACCT_FORK )) {
    EventFork rec( ParentP, this );

    rec.Write();
    }

    return ff.ret = 0; // OK

    } // tProc::Fork

    --- PyGate Linux v1.5.19
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From Tristan Wibberley@3:633/10 to All on Mon Nov 23 22:49:59 2026
    On 21/11/2026 17:22, Bonita Montero wrote:
    ÿÿÿÿÿÿÿ if( !m_enabled )
    ÿÿÿÿÿÿÿÿÿÿÿ return;
    ÿÿÿÿÿÿÿ m_fn();

    This might re-enter which is probably counter-intuitive for the role of
    a scope guard. Setting m_enabled to false before evaluating "m_fn()"
    might be better.

    --
    Tristan Wibberley

    The message body is Copyright (C) 2026 Tristan Wibberley except
    citations and quotations noted. All Rights Reserved except that you may,
    of course, cite it academically giving credit to me, distribute it
    verbatim as part of a usenet system or its archives, and use it to
    promote my greatness and general superiority without misrepresentation
    of my opinions other than my opinion of my greatness and general
    superiority which you _may_ misrepresent. You definitely MAY NOT train
    any production AI system with it but you may train experimental AI that
    will only be used for evaluation of the AI methods it implements.

    --- PyGate Linux v1.5.19
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From Tristan Wibberley@3:633/10 to All on Tue Nov 24 00:12:36 2026
    On 21/11/2026 17:22, Bonita Montero wrote:

    ÿÿÿÿstatic_assert( std::is_nothrow_invocable_v<Fn> );
    The facility is here eliciting the feeling that, by using it, one may disregard the possibility that exceptions pass out of it's members and destructor or that exceptions passing out of the callbacks I provide to
    it are unable to affect its behaviours that I intuitively expect.
    However, only Fn is tested for being nothrow invocable. There are also
    ::run and ::disable of the dependency node to consider.

    There is much to talk about on interface design so this would be
    longwinded and annoying if I did. I wonder if it's better to work with
    client callbacks that throw exceptions so the surprises of the limited compose-ability are removed. I suppose it depends on the scale of the development that the class is being used in.

    Does C++ still allow noexcept(false) destructors and does an exception
    at the end of a destructor allow the members to be destroyed? My memory
    failed in the last few years and I can't remember - I think it does but
    I can't bring a justification for the belief to mind, I think I
    previously relied on advice from journalists that it does.
    Then there would be some thought needed for how exceptions from m_fn()
    and m_pDep::run() interact, c++ has nested exceptions now doesn't it so
    a list can be collected up can't it, which would be sufficient for this particular facility being that it's list-like.

    --
    Tristan Wibberley

    The message body is Copyright (C) 2026 Tristan Wibberley except
    citations and quotations noted. All Rights Reserved except that you may,
    of course, cite it academically giving credit to me, distribute it
    verbatim as part of a usenet system or its archives, and use it to
    promote my greatness and general superiority without misrepresentation
    of my opinions other than my opinion of my greatness and general
    superiority which you _may_ misrepresent. You definitely MAY NOT train
    any production AI system with it but you may train experimental AI that
    will only be used for evaluation of the AI methods it implements.

    --- PyGate Linux v1.5.19
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From Bonita Montero@3:633/10 to All on Tue Nov 24 07:12:56 2026
    Am 24.11.2026 um 01:12 schrieb Tristan Wibberley:

    The facility is here eliciting the feeling that, by using it, one may disregard the possibility that exceptions pass out of it's members and destructor or that exceptions passing out of the callbacks I provide to
    it are unable to affect its behaviours that I intuitively expect.
    However, only Fn is tested for being nothrow invocable. There are also ::run and ::disable of the dependency node to consider.

    My template trickery checks if the dependent node is a
    defer<>; so it's also checked if it's fn is also noexcept.

    There is much to talk about on interface design so this would be longwinded and annoying if I did. I wonder if it's better to work with
    client callbacks that throw exceptions so the surprises of the limited compose-ability are removed. I suppose it depends on the scale of the development that the class is being used in.

    I thought about that for a while and I came to the conclusion that this
    scope guard isn't different from a normal destructor, which is noexcept
    by default; so I did it the same way to enforce Fn to be noexcept.

    Does C++ still allow noexcept(false) destructors and does an exception
    at the end of a destructor allow the members to be destroyed? ...
    Yes, you can do that; but I guess that's very uncommon.

    --- PyGate Linux v1.5.19
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From Tristan Wibberley@3:633/10 to All on Tue Nov 24 12:42:02 2026
    On 24/11/2026 06:12, Bonita Montero wrote:
    Am 24.11.2026 um 01:12 schrieb Tristan Wibberley:

    ÿÿ The facility is here eliciting the feeling that, by using it, one may
    disregard the possibility that exceptions pass out of it's members and
    destructor or that exceptions passing out of the callbacks I provide to
    it are unable to affect its behaviours that I intuitively expect.
    ÿÿ However, only Fn is tested for being nothrow invocable. There are also
    ::run and ::disable of the dependency node to consider.

    My template trickery checks if the dependent node is a
    defer<>; so it's also checked if it's fn is also noexcept.

    Oh! I didn't notice that.


    ÿÿ There is much to talk about on interface design so this would be
    longwinded and annoying if I did. I wonder if it's better to work with
    client callbacks that throw exceptions so the surprises of the limited
    compose-ability are removed. I suppose it depends on the scale of the
    development that the class is being used in.

    I thought about that for a while and I came to the conclusion that this
    scope guard isn't different from a normal destructor, which is noexcept
    by default; so I did it the same way to enforce Fn to be noexcept.

    Does C++ still allow noexcept(false) destructors and does an exception
    at the end of a destructor allow the members to be destroyed? ...
    Yes, you can do that; but I guess that's very uncommon.

    Of course it wasn't so until C++14 when the preset mode was changed from noexcept(false) to noexcept(true) (was it C++14?), and before C++11
    there wasn't even a way to change it /from/ noexcept(false). So I think
    it's really common. A unix workstation multi-process application
    exhibits the most ordinary behaviours around success, failure, and
    cleanup when relying on that feature (which probably explains why it was
    the only easy way to do things in C++ until C++11 and was the default
    until C++14.

    There are also core aspects of meaning about trying to rollback/reset
    and throwing if you can't rollback/reset and then aborting if you can't
    reset something. Here's the original concept at least from C++98 to
    C++11 (default) and C++14 (nondefault but available).

    You can:
    a) during primary success:
    try to release resource (scope guarding) and:
    1) succeed, or
    2) fail with exception which unwinds (invariants maintained)
    (standard scope guarding - throws from destructor)
    b) during primary failure (unwinding with exception in flight):
    try to release resource (scope guarding) and:
    1) succeed, unwinding of the primary failure continues, or
    2) secondary failure with exception which aborts because an
    primary exception is already in flight
    (invariants not maintained)

    Those are how it was set up to work until C++11, and is obviously
    correct for the limited case where one wants to abort in (b.2) which is
    typical in multiprocess unix applications because invariants are not
    maintained - so continuation is necessarily invalid. When one does not
    make a problem with secondary exceptions having the same type or
    ancestor type as primary exceptions in (a.2) - the dangers in this area
    might have been a motivation for adding noexcept(true) in C++11 and
    defaulting to noexcept(true) in C++14. For most ordinary scope guard
    classes one does not make such a problem.

    C++11 added the ability to change (b.2) so that an exception could be
    nested if a destructor threw when it was being run during unwinding
    instead of aborting. Then you handle the failure-to-handle-a-failure - invariants /are/ maintained in general by conditions, but the immediate surrounding sequence is for a tighter unconditional invariant so you
    unwind that bit only and catch with the looser invariants of a degraded
    mode. I haven't made good use of that but I think it's done wrong and
    ought to have been done via insertion of exception translation functions
    into the handler-search phase because relying on the use of try and
    catch inside scope guards to translate exceptions makes a lot of new
    problems vs. callbacks called at the point of the original "throw".

    We now have nested exceptions so we can structure code as the above with
    the below (a,b,c.i) and add in (c.ii) when (c.i) is invalid in some
    special places like O/S executives where scope guards maintain
    invariants over shared factors. However, I don't know how it goes when
    you go and compose larger programs using the same pattern arbitrarily
    deeply because I haven't used the feature.


    a) assumed events:
    - flow-through
    b) assumed events during reset from detection of unassumed event:
    - destroy objects during unwinding
    c) assumed events during reset from detection of unassumed event
    during reset from detection of unassumed event:
    - either:
    i) throw during unwinding destruction and therefrom terminate
    instead of unwinding further, or
    ii) throw during unwinding destruction storing the original
    exception as nested exception

    (a) - everyone knows and uses it
    (b) - very popular (scope guards rely on it)
    (c.i) - some people spend a lot of effort avoiding it and making
    programs understandable only in tunnel focus
    In fact, it is merely (b) with the ability to add on "and if
    handling further errors gracefully is too hard, just abort
    like everyone else does"
    (c.ii) - I never got round to looking close enough at it.


    --
    Tristan Wibberley

    The message body is Copyright (C) 2026 Tristan Wibberley except
    citations and quotations noted. All Rights Reserved except that you may,
    of course, cite it academically giving credit to me, distribute it
    verbatim as part of a usenet system or its archives, and use it to
    promote my greatness and general superiority without misrepresentation
    of my opinions other than my opinion of my greatness and general
    superiority which you _may_ misrepresent. You definitely MAY NOT train
    any production AI system with it but you may train experimental AI that
    will only be used for evaluation of the AI methods it implements.

    --- PyGate Linux v1.5.19
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From Bonita Montero@3:633/10 to All on Tue Nov 24 15:01:50 2026
    Am 24.11.2026 um 13:42 schrieb Tristan Wibberley:

    Of course it wasn't so until C++14 when the preset mode was changed from noexcept(false) to noexcept(true) (was it C++14?), and before C++11
    there wasn't even a way to change it /from/ noexcept(false).

    It wasn't handled differently with any C++-version, meaning
    that destructors that throw exceptions are nearly no existing.

    So I think it's really common.

    It's dangerous: If an exception occurs while unwinding the stack of a
    function the unwinding continues and when it is finished the exception
    is propagated upwards. But if you have a second exception while this
    unwinding happens the application is terminated.

    A unix workstation multi-process application exhibits the most ordinary behaviours around success, failure, and cleanup when relying on that
    feature (which probably explains why it was the only easy way to do
    things in C++ until C++11 and was the default until C++14.

    Show me some libs that have a noexcept( false ) destructor.

    Rest unread.


    --- PyGate Linux v1.5.19
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From Ross Finlayson@3:633/10 to All on Tue Nov 24 08:59:12 2026
    On 11/24/2026 04:42 AM, Tristan Wibberley wrote:
    On 24/11/2026 06:12, Bonita Montero wrote:
    Am 24.11.2026 um 01:12 schrieb Tristan Wibberley:

    The facility is here eliciting the feeling that, by using it, one may >>> disregard the possibility that exceptions pass out of it's members and
    destructor or that exceptions passing out of the callbacks I provide to
    it are unable to affect its behaviours that I intuitively expect.
    However, only Fn is tested for being nothrow invocable. There are also >>> ::run and ::disable of the dependency node to consider.

    My template trickery checks if the dependent node is a
    defer<>; so it's also checked if it's fn is also noexcept.

    Oh! I didn't notice that.


    There is much to talk about on interface design so this would be
    longwinded and annoying if I did. I wonder if it's better to work with
    client callbacks that throw exceptions so the surprises of the limited
    compose-ability are removed. I suppose it depends on the scale of the
    development that the class is being used in.

    I thought about that for a while and I came to the conclusion that this
    scope guard isn't different from a normal destructor, which is noexcept
    by default; so I did it the same way to enforce Fn to be noexcept.

    Does C++ still allow noexcept(false) destructors and does an exception
    at the end of a destructor allow the members to be destroyed? ...
    Yes, you can do that; but I guess that's very uncommon.

    Of course it wasn't so until C++14 when the preset mode was changed from noexcept(false) to noexcept(true) (was it C++14?), and before C++11
    there wasn't even a way to change it /from/ noexcept(false). So I think
    it's really common. A unix workstation multi-process application
    exhibits the most ordinary behaviours around success, failure, and
    cleanup when relying on that feature (which probably explains why it was
    the only easy way to do things in C++ until C++11 and was the default
    until C++14.

    There are also core aspects of meaning about trying to rollback/reset
    and throwing if you can't rollback/reset and then aborting if you can't
    reset something. Here's the original concept at least from C++98 to
    C++11 (default) and C++14 (nondefault but available).

    You can:
    a) during primary success:
    try to release resource (scope guarding) and:
    1) succeed, or
    2) fail with exception which unwinds (invariants maintained)
    (standard scope guarding - throws from destructor)
    b) during primary failure (unwinding with exception in flight):
    try to release resource (scope guarding) and:
    1) succeed, unwinding of the primary failure continues, or
    2) secondary failure with exception which aborts because an
    primary exception is already in flight
    (invariants not maintained)

    Those are how it was set up to work until C++11, and is obviously
    correct for the limited case where one wants to abort in (b.2) which is typical in multiprocess unix applications because invariants are not maintained - so continuation is necessarily invalid. When one does not
    make a problem with secondary exceptions having the same type or
    ancestor type as primary exceptions in (a.2) - the dangers in this area
    might have been a motivation for adding noexcept(true) in C++11 and defaulting to noexcept(true) in C++14. For most ordinary scope guard
    classes one does not make such a problem.

    C++11 added the ability to change (b.2) so that an exception could be
    nested if a destructor threw when it was being run during unwinding
    instead of aborting. Then you handle the failure-to-handle-a-failure - invariants /are/ maintained in general by conditions, but the immediate surrounding sequence is for a tighter unconditional invariant so you
    unwind that bit only and catch with the looser invariants of a degraded
    mode. I haven't made good use of that but I think it's done wrong and
    ought to have been done via insertion of exception translation functions
    into the handler-search phase because relying on the use of try and
    catch inside scope guards to translate exceptions makes a lot of new
    problems vs. callbacks called at the point of the original "throw".

    We now have nested exceptions so we can structure code as the above with
    the below (a,b,c.i) and add in (c.ii) when (c.i) is invalid in some
    special places like O/S executives where scope guards maintain
    invariants over shared factors. However, I don't know how it goes when
    you go and compose larger programs using the same pattern arbitrarily
    deeply because I haven't used the feature.


    a) assumed events:
    - flow-through
    b) assumed events during reset from detection of unassumed event:
    - destroy objects during unwinding
    c) assumed events during reset from detection of unassumed event
    during reset from detection of unassumed event:
    - either:
    i) throw during unwinding destruction and therefrom terminate
    instead of unwinding further, or
    ii) throw during unwinding destruction storing the original
    exception as nested exception

    (a) - everyone knows and uses it
    (b) - very popular (scope guards rely on it)
    (c.i) - some people spend a lot of effort avoiding it and making
    programs understandable only in tunnel focus
    In fact, it is merely (b) with the ability to add on "and if
    handling further errors gracefully is too hard, just abort
    like everyone else does"
    (c.ii) - I never got round to looking close enough at it.




    Thanks for writing, an account of noexcept in the signature vis-a-vis
    nodiscard as attribute about the signature and the exception-signature,
    has it so that in scope-managed like block-scoped and function-scoped
    resource management, that exceptions are a true way in the language
    to give the guaranteed behavior of propagation of errors from deeper
    than the shallow in the usual account of a function-stack.


    That the industry has leaned away from exceptions since untrusted
    or 3'rd party code, or, bugs, otherwise would result trashing the
    stack, or "goto isn't good or bad, it just is", then considered
    to patch that back together with nodiscard prodding discipline,
    doesn't take it away from the language that exception-handling
    the stack-unwinding is already well-defined.


    The account of exception-translation, for example about asynchronous
    code which is basically covariant and about "generic" or "in-specific"
    or "wrapped" exceptions vis-a-vis that's just the error code and
    accounts of, for example, "structured errors", and since "structured
    exception handling", in the system and the language, has the usual
    account that code that swallows exceptions that aren't specifically
    modeled after error-modeling and exception-modeling as well-defined,
    is undefined behavior.


    Java and C++ have a lot of sympatico, basically since Java's inception
    and "hide all the pointers, everything's a pointer, we'll refcount
    the pointers", then for class theory and type theory, for example
    about C++'s "multiple inheritance" account vis-a-vis Java's "single inheritance" account then with Java's interfaces cum C++'s concepts,
    of course these things have been observed by anybody familiar with
    the development and maturations of these languages on their systems
    their eco-systems.


    Accounts of ownership and responsibility basically make for distinctions
    in types that any "move" is a "copy", that it's
    sort of a helper and dodgy what lives up-the-stack vis-a-vis
    what lives down-the-stack, which shows itself in the _holes_
    of "ref ref" or "&&" where pointers have multiple purposes
    and should basically have own types, about "quantifier disambiguation"
    then "pointer disambiguation" which is these days that "universal"
    or, what was that, "forwarding references" or "ref ref", is
    a bit the bitter pill the syntactic sugar.








    --- PyGate Linux v1.5.19
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From Tristan Wibberley@3:633/10 to All on Tue Nov 24 19:04:12 2026
    On 24/11/2026 14:01, Bonita Montero wrote:
    Am 24.11.2026 um 13:42 schrieb Tristan Wibberley:

    Of course it wasn't so until C++14 when the preset mode was changed from
    noexcept(false) to noexcept(true) (was it C++14?), and before C++11
    there wasn't even a way to change it /from/ noexcept(false).

    It wasn't handled differently with any C++-version, meaning
    that destructors that throw exceptions are nearly no existing.

    So I think it's really common.

    It's dangerous: If an exception occurs while unwinding the stack of a function the unwinding continues and when it is finished the exception
    is propagated upwards. But if you have a second exception while this unwinding happens the application is terminated.

    That's what I think is the goal in many applications. That's what noexcept(false) is for. noexcept(true) is for when you want the
    termination every time an exception would leak from a destructor with
    runtime checks in case you made a booboo.

    When the invariants are not maintained it's dangerous to continue, the
    future should be broadly as if power were lost by the host or a process
    kill occurs (memory unit mapped into process memory is lost, etc).

    If you could continue safely then you can re-establish the invariant
    within the destructor by all sorts of means. You can throw and handle exceptions within the destructor without terminating, it is only leaking
    of the secondary exception out of the destructor that causes termination.

    The rest of the system should gracefully continue thereby making it safe
    (eg, failover, rapid restart, etc).

    Safety involves not running a program segment when its invariants do not
    hold. That much is fundamental. If you can run it then its invariants
    perhaps are more conditional after all (perhaps the system has processes
    and failover, stochastic redundancy and quora, etc) and maybe then you
    don't need any cleanup for a code segment (no problem no scope guard).


    --
    Tristan Wibberley

    The message body is Copyright (C) 2026 Tristan Wibberley except
    citations and quotations noted. All Rights Reserved except that you may,
    of course, cite it academically giving credit to me, distribute it
    verbatim as part of a usenet system or its archives, and use it to
    promote my greatness and general superiority without misrepresentation
    of my opinions other than my opinion of my greatness and general
    superiority which you _may_ misrepresent. You definitely MAY NOT train
    any production AI system with it but you may train experimental AI that
    will only be used for evaluation of the AI methods it implements.

    --- PyGate Linux v1.5.19
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From Tristan Wibberley@3:633/10 to All on Tue Nov 24 19:20:25 2026
    On 24/11/2026 19:04, Tristan Wibberley wrote:
    You can throw and handle
    exceptions within the destructor without terminating, it is only leaking
    of the secondary exception out of the destructor that causes termination.
    Hang on, my memory is kicking-in some nuance and that the above is not
    outright true. Before C++11 there were more restrictions and the safe
    abort had to happen in more situations. C++11 added some features that
    made some things easier to do without aborting as much.

    I will have to refresh my memory to be able to give my perspective further.

    --
    Tristan Wibberley

    The message body is Copyright (C) 2026 Tristan Wibberley except
    citations and quotations noted. All Rights Reserved except that you may,
    of course, cite it academically giving credit to me, distribute it
    verbatim as part of a usenet system or its archives, and use it to
    promote my greatness and general superiority without misrepresentation
    of my opinions other than my opinion of my greatness and general
    superiority which you _may_ misrepresent. You definitely MAY NOT train
    any production AI system with it but you may train experimental AI that
    will only be used for evaluation of the AI methods it implements.

    --- PyGate Linux v1.5.19
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From Ross Finlayson@3:633/10 to All on Tue Nov 24 11:22:20 2026
    On 11/24/2026 11:04 AM, Tristan Wibberley wrote:
    On 24/11/2026 14:01, Bonita Montero wrote:
    Am 24.11.2026 um 13:42 schrieb Tristan Wibberley:

    Of course it wasn't so until C++14 when the preset mode was changed from >>> noexcept(false) to noexcept(true) (was it C++14?), and before C++11
    there wasn't even a way to change it /from/ noexcept(false).

    It wasn't handled differently with any C++-version, meaning
    that destructors that throw exceptions are nearly no existing.

    So I think it's really common.

    It's dangerous: If an exception occurs while unwinding the stack of a
    function the unwinding continues and when it is finished the exception
    is propagated upwards. But if you have a second exception while this
    unwinding happens the application is terminated.

    That's what I think is the goal in many applications. That's what noexcept(false) is for. noexcept(true) is for when you want the
    termination every time an exception would leak from a destructor with
    runtime checks in case you made a booboo.

    When the invariants are not maintained it's dangerous to continue, the
    future should be broadly as if power were lost by the host or a process
    kill occurs (memory unit mapped into process memory is lost, etc).

    If you could continue safely then you can re-establish the invariant
    within the destructor by all sorts of means. You can throw and handle exceptions within the destructor without terminating, it is only leaking
    of the secondary exception out of the destructor that causes termination.

    The rest of the system should gracefully continue thereby making it safe
    (eg, failover, rapid restart, etc).

    Safety involves not running a program segment when its invariants do not hold. That much is fundamental. If you can run it then its invariants
    perhaps are more conditional after all (perhaps the system has processes
    and failover, stochastic redundancy and quora, etc) and maybe then you
    don't need any cleanup for a code segment (no problem no scope guard).




    Seems you need model your resource-management that has clean-up
    side-effects as first-class or its own synchronization, since
    destructors should have no side effects (that can throw) so that their
    clean-up of otherwise the stack with invoking all their destructors
    with all their none side-effects, maintains well-defined behavior,
    that it seems that anonymous-routine of lambda-off-the-destructor
    introduces its own execution context anyways and isn't consistent
    with other more basic accounts of "defined behavior", i.e. it's not.

    One might imagine that as the language has grown that there are
    other conflicting accounts of "defined behavior".

    The very-point of error-modeling and exception-modeling is
    deemed necessary to "maintain invariants".



    "The estimated lifetime of an instance of [httpd] here
    before it dies randomly is 23 minutes. When it dies
    its last request is sent to a new one."

    This is longer than a usual account of "lull in conversation",
    which was widely estimated since forty or more years ago,
    as 17 minutes, though some aver 7 minutes.

    "Why not save it?" "Tragedy of the commons."


    "How about that queue over there?" "Oh, that can't go down at all."




    I always write const/volatile qualifiers _after_ where it's associated,
    instead of before, and always make the pointer or reference part of
    the _type_ not the _value_, since it's not like "int x = 0, *px = &x",
    that those are _operations_ not _qualifiers_, about then mostly
    assignment or "=", the "operator".




    --- PyGate Linux v1.5.19
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From Tristan Wibberley@3:633/10 to All on Tue Nov 24 19:24:39 2026
    On 24/11/2026 16:59, Ross Finlayson wrote:
    has the usual
    account that code that swallows exceptions that aren't specifically
    modeled after error-modeling and exception-modeling as well-defined,
    is undefined behavior.

    And so much for catch (...).

    If I can, I prefer to fork a child process and let the exception be
    handle by process abort of uncaught exceptions, the wider loop absorbs
    it with invariants intact (the missing process makes its own invariants
    go away - at the system level they're conditional on their own process existing).

    --
    Tristan Wibberley

    The message body is Copyright (C) 2026 Tristan Wibberley except
    citations and quotations noted. All Rights Reserved except that you may,
    of course, cite it academically giving credit to me, distribute it
    verbatim as part of a usenet system or its archives, and use it to
    promote my greatness and general superiority without misrepresentation
    of my opinions other than my opinion of my greatness and general
    superiority which you _may_ misrepresent. You definitely MAY NOT train
    any production AI system with it but you may train experimental AI that
    will only be used for evaluation of the AI methods it implements.

    --- PyGate Linux v1.5.19
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From Tristan Wibberley@3:633/10 to All on Tue Nov 24 20:18:28 2026
    On 24/11/2026 19:22, Ross Finlayson wrote:
    destructors should have no side effects (that can throw)

    That's merely a deduction from contensive ontology which, as you know,
    is typically a matter of fantasy: 'I call them "destructor" therefore
    they should not throw'. But their extensional properties are of things
    that can throw: "Throwing in them can mean the right thing therefore
    they may throw".

    In fact they're scope-hooks at the same time so which of the succeeding
    program addresses (Dijkstra) should run after they run and in which
    conditions is the important question: "all of them all of the time" is
    not correct.

    --
    Tristan Wibberley

    The message body is Copyright (C) 2026 Tristan Wibberley except
    citations and quotations noted. All Rights Reserved except that you may,
    of course, cite it academically giving credit to me, distribute it
    verbatim as part of a usenet system or its archives, and use it to
    promote my greatness and general superiority without misrepresentation
    of my opinions other than my opinion of my greatness and general
    superiority which you _may_ misrepresent. You definitely MAY NOT train
    any production AI system with it but you may train experimental AI that
    will only be used for evaluation of the AI methods it implements.

    --- PyGate Linux v1.5.19
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From Ross Finlayson@3:633/10 to All on Tue Nov 24 12:48:34 2026
    On 11/24/2026 12:18 PM, Tristan Wibberley wrote:
    On 24/11/2026 19:22, Ross Finlayson wrote:
    destructors should have no side effects (that can throw)

    That's merely a deduction from contensive ontology which, as you know,
    is typically a matter of fantasy: 'I call them "destructor" therefore
    they should not throw'. But their extensional properties are of things
    that can throw: "Throwing in them can mean the right thing therefore
    they may throw".

    In fact they're scope-hooks at the same time so which of the succeeding program addresses (Dijkstra) should run after they run and in which conditions is the important question: "all of them all of the time" is
    not correct.


    That's agreeable as to that it seems sensible,
    though, for whether it's "made sense",
    besides, "makes sense".


    Sometimes a "C++-minus" is going to be safer than "C++ any-which-way".

    Like you said about exception-translation, exception-translation is a first-class sort of account about a convention, since neither the
    language nor the compiler otherwise says, i.e., it's "undefined".

    I.e., either you make exception-translation or you don't, then
    also has the usual account that the destructor's function that
    throws mid-function exits the function and leaves with the
    thread-of-control, as it were, unfinished the destructor-body.

    Otherwise the usual account of exception throwing as "roll up all
    the automatics, like any other account of exiting block and function
    scope, until the exception is caught", is most what it says.


    What's defined is when "dtors run once for each ctor in reverse-order
    however which way the function exits, or the thread of it the function departs", according to the language what the compiler must generate as code.

    Of course it matters not so much what I say as what it is,
    then that the written account speaks for itself in a particularly
    sort of durable, irrepudiable statement.

    Thanks for writing, good luck in your endeavors.



    --- PyGate Linux v1.5.19
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)