Skip to content

Stop throwing from destructors

James Willenbring requested to merge ibaned:throwing-from-dtors into develop

Created by: ibaned

@trilinos/teuchos @trilinos/thyra @trilinos/belos @trilinos/ml @lxmota

Description

From the first commit message:

This is the foundation for fixing #1303 (closed). First, the macro TEUCHOS_TEST_FOR_TERMINATION is introduced, which calls std::terminate() instead of throwing an exception.

I think std::terminate() is the most appropriate exit call here, because it is exactly what the compiler would have done anyway. In particular, the warnings we were getting said "warning: throw will always call terminate() [-Wterminate]" As such, if we explicitly call std::terminate ourselves, we are preserving the existing behavior while silencing the warning.

TEUCHOS_TEST_FOR_TERMINATION takes stream message code, and that message will be sent to std::cerr.

This commit also replaces all calls in Teuchos, Belos, Thyra, and ML to TEUCHOS_TEST_FOR_EXCEPTION (and similar macros) from within destructors with TEUCHOS_TEST_FOR_TERMINATION.

Motivation and Context

See #1303 (closed) for general discussion, but here is some data to put this issue into perspective, also from the first commit message:

The most important change is the one in ~RCPNodeTmpl() in Teuchos_RCPNode.hpp which is guarded by TEUCHOS_DEBUG. When TEUCHOS_DEBUG is defined, this instance alone emitted its warning at least 136702 times in one user's reported build of Trilinos, due to the ubuquitous use of RCP in Trilinos. Given that one warning and its associated notes are close to 1KB of text, this dominated and bloated all other build output for a total of around 100MB of text output from the build.

Related Issues

How Has This Been Tested?

A debug build of only Teuchos with -Werror and TEUCHOS_DEBUG defined built successfully and passed all Teuchos tests. Will rely on PR testing as well.

Checklist

  • My commit messages mention the appropriate GitHub issue numbers.
  • My code follows the code style of the affected package(s).
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the code contribution guidelines for this project.
  • I have added tests to cover my changes.
  • All new and existing tests passed.
  • No new compiler warnings were introduced.
  • These changes break backwards compatibility.

Merge request reports