numenta / nupic.core-legacy

Implementation of core NuPIC algorithms in C++ (under construction)
http://numenta.org
GNU Affero General Public License v3.0
272 stars 276 forks source link

Build error: throw will always call terminate #1414

Open mewmew opened 6 years ago

mewmew commented 6 years ago

When trying to build nupic.core at rev 7d66fc32c65358d3759c6794c6ddb1ce7d33ab79, I received the following error message:

/home/u/Desktop/numenta_play/nupic_core_aur/src/nupic.core/src/nupic/engine/Output.cpp: In destructor ‘nupic::Output::~Output()’:
/home/u/Desktop/numenta_play/nupic_core_aur/src/nupic.core/src/nupic/engine/Output.cpp:49:36: error: throw will always call terminate() [-Werror=terminate]
   NTA_CHECK(links_.size() == 0) << "Internal error in region deletion";
                                    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/u/Desktop/numenta_play/nupic_core_aur/src/nupic.core/src/nupic/engine/Output.cpp:49:36: note: in C++11 destructors default to noexcept
cc1plus: all warnings being treated as errors
make[2]: *** [src/CMakeFiles/nupic_core_solo.dir/build.make:1489: src/CMakeFiles/nupic_core_solo.dir/nupic/engine/Output.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:713: src/CMakeFiles/nupic_core_solo.dir/all] Error 2
make: *** [Makefile:152: all] Error 2
==> ERROR: A failure occurred in build().
mewmew commented 6 years ago

Additional info:

u@x220 ~/D/n/nupic_core_aur> gcc --version
gcc (GCC) 7.3.1 20180312
Copyright (C) 2017 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
u@x220 ~/D/n/nupic_core_aur> clang --version
clang version 6.0.0 (tags/RELEASE_600/final)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
mewmew commented 6 years ago

Note, a comment states that throwing an exception from within the destructor is intended, even if "not good".

Output::~Output() {
  // If we have any outgoing links, then there has been an
  // error in the shutdown process. Not good to thow an exception
  // from a destructor, but we need to catch this error, and it
  // should never occur if nupic internal logic is correct.
  NTA_CHECK(links_.size() == 0) << "Internal error in region deletion";
  delete data_;
}
mewmew commented 6 years ago

WIth -Wno-error=terminate added, the build finishes successfully.

diff --git a/CommonCompilerConfig.cmake b/CommonCompilerConfig.cmake
index a2b2a534..05eed935 100644
--- a/CommonCompilerConfig.cmake
+++ b/CommonCompilerConfig.cmake
@@ -260,8 +260,8 @@ else()
   endif()

   set(shared_compile_flags "${shared_compile_flags} ${stdlib_common} -fdiagnostics-show-option")
-  set (internal_compiler_warning_flags "${internal_compiler_warning_flags} -Werror -Wextra -Wreturn-type -Wunused -Wno-unused-variable -Wno-unused-parameter -Wno-missing-field-initializers")
-  set (external_compiler_warning_flags "${external_compiler_warning_flags} -Wno-unused-variable -Wno-unused-parameter -Wno-incompatible-pointer-types -Wno-deprecated-declarations")
+  set (internal_compiler_warning_flags "${internal_compiler_warning_flags} -Werror -Wextra -Wreturn-type -Wunused -Wno-error=terminate -Wno-unused-variable -Wno-unused-parameter -Wno-missing-field-initializers")
+  set (external_compiler_warning_flags "${external_compiler_warning_flags} -Wno-error=terminate -Wno-unused-variable -Wno-unused-parameter -Wno-incompatible-pointer-types -Wno-deprecated-declarations")

   CHECK_CXX_COMPILER_FLAG(-m${BITNESS} compiler_supports_machine_option)
   if (compiler_supports_machine_option)
rhyolight commented 6 years ago

I don't know the history here. This has not been failing in any of our CI builds. What OS is this? I'm not sure adding this option is the right thing to do. @lscheinkman?

mewmew commented 6 years ago

Hi Matthew,

I don't know the history here. This has not been failing in any of our CI builds. What OS is this? I'm not sure adding this option is the right thing to do. @lscheinkman?

My guess is that it has to do with never versions of GCC. My version of GCC outputs a warning (7.3.1 20180312) since an exception is thrown in a destructor, and the build is set to treat warnings as errors; thus causing the build to fail.

As for OS, I'm running Arch Linux,

u@x220 ~> uname -a
Linux x220 4.15.15-1-ARCH #1 SMP PREEMPT Sat Mar 31 23:59:25 UTC 2018 x86_64 GNU/Linux

Let me know if you require any additional information.

Cheers /u

P.S. Thanks Matthew for putting the HTM school videos up on YouTube, they've been fun to follow.

rhyolight commented 6 years ago

I'll keep an eye out for GCC failures like this being reported. Thanks for writing this up.

breznak commented 6 years ago

Btw, duplicate of #1000

breznak commented 5 years ago

:-1: for the proposed fix with Wno-error=terminate, the culpit is in NTA_CHECK (can throw) in ~destructor! That should be solved. There's an issue already about that topic.. #1317