Skip to content
This repository has been archived by the owner on Sep 1, 2023. It is now read-only.

Fails to compile with GCC 6.x - make destructors noexcept #1317

Open
breznak opened this issue May 22, 2017 · 3 comments
Open

Fails to compile with GCC 6.x - make destructors noexcept #1317

breznak opened this issue May 22, 2017 · 3 comments

Comments

@breznak
Copy link
Member

breznak commented May 22, 2017

Testing the latest & greatest gcc compiler, I run into some issues.

  • about the use of NTA_CHECK(..) << "msg" macro:
[ 40%] Building CXX object src/CMakeFiles/nupic_core_solo.dir/nupic/engine/Region.cpp.o
/home/mmm/devel/HTM/nupic.core/src/nupic/engine/Output.cpp: In destructor ‘nupic::Output::~Output()’:
/home/mmm/devel/HTM/nupic.core/src/nupic/engine/Output.cpp:51:36: error: throw will always call terminate() [-Werror=terminate]
   NTA_CHECK(links_.size() == 0) << "Internal error in region deletion";
                                    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/mmm/devel/HTM/nupic.core/src/nupic/engine/Output.cpp:51:36: note: in C++11 destructors default to noexcept

Looks like we'll have to rewrite these macros

@vitaly-krugl
Copy link
Member

I think this makes sense. We generally don't want the possibility of an exception within the scope of a destructor. Good read on the subject: http://bin-login.name/ftp/pub/docs/programming_languages/cpp/cffective_cpp/MEC/MI11_FR.HTM

@breznak
Copy link
Member Author

breznak commented May 22, 2017

So, how do we do it? Compile with Wno-error=terminate? Or better yet something like #pragma push to silence it only for the NTA_CHECK/ASSERT macros?

@vitaly-krugl
Copy link
Member

vitaly-krugl commented May 22, 2017

We should have a common approach for all C++ destructors. Effective C++ talks about two problems concerning exceptions in destructors:

  1. terminate in case exception from a destructor flows to another destructor in higher scope
  2. incomplete destruction/release of resources in case of exception in destructor

I think that we should either avoid using anything in a destructor that could raise an exception or wrap code in a simple try with an empty-bodied catch as recommended in http://bin-login.name/ftp/pub/docs/programming_languages/cpp/cffective_cpp/MEC/MI11_FR.HTM.

Calling NTA_CHECK from a destructor would be an oxymoron. Perhaps something like NTA_WARN_NO_EXC (doesn't exist yet) would be a more appropriate alternative for this specific scenario.

@breznak breznak changed the title Fails to compile with GCC 6.x Fails to compile with GCC 6.x - make destructors noexcept May 22, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants