c++ - Is there any trick to detect if an object is created during execution of another destructor? -
this kind of follow on why cant alexandrescu utilize std::uncaught_exception() implement scope_fail in scopeguard11?
i observe if creating myclass
in destructor of class (or active destructor somewhere in phone call stack).
class myclass { public: myclass(){ assert(???what set here????); } } void f(){ myclass m; //whether asserts should context dependant } class otherclass{ ~otherclass(){ myclass m; //this should assert f(); //this should too; } } int main() { myclass m; //this should not assert f(); //this should not assert }
one effort might be:
assert(!std::uncaught_exception());
but work if destructor beingness invoked because of exception, not if invoked because object went out of scope.
you cannot observe , don't want to. it's not class's business. if phone call noexcept destructor, grab exceptions
c++ destructor uncaught-exception stack-unwinding
No comments:
Post a Comment