Warranty noexcept and reliability

I recently tried to answer what, in my opinion, was a simple question in the exception specification noexcept. As a result, I found that my fundamental understanding noexceptwas wrong.

While reading the current draft of the standard , in order to correct my misunderstanding, I found that I was asking a few questions about noexceptwhich I did not answer here .

  • Should it noexceptbe considered a guarantee of security that the function will not only not quit, but also not ruin the state when called?
  • Assuming that (1.) is incorrect: is it correct to use FailFastnoexcept as a portable to terminate the application without cleaning to prevent damage to the saved state?

Clarification to (2.): The goal is only to prevent the destructor from noexceptbeing called further up the stack to prevent unwinding inside it. This is based on the assumption that this is an ideal RAII environment, and the destructors on the stack can put the global state into constancy, thus corrupting it.

An example of how unwinding is not performed:

#include <iostream>
#include <exception>

namespace{
   struct foo{
       void change_state() noexcept
       {
          // change state and fail
          throw std::exception();
       }
       ~foo(){
          std::cout << "Destructor called, saved state corrupted!" <<std::endl;
       }
    };
}


int main(){
    ::std::set_terminate([](){
        std::cout<< "Terminate called" <<std::endl;
    });

    foo f;
    f.change_state();
    return 0;
}

Working example noexcept

+3
source share
2 answers
  • . , , , . , , , , . [, , . .; -)]
  • Mu. , noexcept; std::terminate ( std::abort).
+2

noexcept , assert . , noexcept , - , -; . , 1 .

2, . , noexcept; 100% ( ), . , abort(), - . , , .

+1

All Articles