9

Here is the portion of code I speak about.

try {
       std::cerr << "first try" << std::endl;
       po::store(po::parse_config_file(ifs, _configFileOptions, false), vm);

} catch(...) {           
       std::cerr << "second try" << std::endl;            
}

Just for the seek of details , I m using boost program_options to parse a configuration file. An exception is raised by boost since I put an option in the file that is unrecognized.

There is a problem with Clang not catching this exception. Basically I only see in the output

first try
libc++abi.dylib: terminating with uncaught exception of type boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<boost::program_options::unknown_option> >: unrecognised option 'TestFrequency'
Abort trap: 6

Here is my clang version:

c++ --version
Apple LLVM version 7.3.0 (clang-703.0.31)
Target: x86_64-apple-darwin15.6.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

EDIT: When there is no exception, the parsing and everything works fine.

Issam T.
  • 1,677
  • 1
  • 14
  • 32
  • 2
    What version of boost do you have? Maybe you have better luck using catch(std::exception&) – Trevir Sep 26 '16 at 14:41
  • boost 1.55. Everything is compiled with Clang against libC++. and yes i tried catch(std::exception&) before submitting the question but it didn t work. – Issam T. Sep 26 '16 at 14:54
  • 1
    this is common when boost and the exe are compiled against different standard libraries (i know you mentioned this, but check again). – Richard Hodges Sep 26 '16 at 15:03
  • @RichardHodges Thanks. I will double check. but shouldn't it throw errors at link time if it is the case? – Issam T. Sep 26 '16 at 15:50
  • I checked. Everything is compiled against libC++. I compiled another boost with libstdc++ and i had link error : undefined symbols. – Issam T. Sep 27 '16 at 06:35
  • The problem with my issue is that everything works as expected unless there is an exception. I know my error comes from some incompatibility in the compilation but why does the linker accept to link incompatible libraries? As if C++ wasn't already enough complex, we added multiple ABI compilers to have more fun – Issam T. Sep 27 '16 at 06:38
  • Have you tried to replace your call with a hardcoded exception throw (`throw 0;` or something similar)? I had problems with GCC (I know it is not related to clang, but just in case) on exception handling when some optimizations were enabled, so compiling with `-O0` is worth trying. – Jorge Bellon Oct 03 '16 at 17:54
  • make sure You don't have misplaced noexcept – MateuszL Oct 06 '16 at 09:44
  • Have you tried adding the -fcxx-exceptions flag to your command-line? – laprej Oct 07 '16 at 02:27
  • For me it don't seem to be a compilation problem but a runtime one related to boost library. What happen if you try to catch error from boost? : catch(po::error& e) { cout << e.what(); } – Raphayol Oct 07 '16 at 11:28
  • 1
    Linker don't check exception ABI compatibility. C++ need a lot standardization on internal implementation that affect linking different modules built by different compiler for rtti, exception ABI and mangle( Now its a pain when you need rebuild all library by one compiler. Hope they will bring some standard with this stuff and not just syntax sugar. – Defter Oct 07 '16 at 14:32

2 Answers2

0

This could be related to the RTTI (Run Time Type Information) issue that is similar to this issue with GoogleMaps or this question on SO.

Make sure that Boost and your code are compiled without fno-rtti flag.

Community
  • 1
  • 1
dreamzor
  • 5,795
  • 4
  • 41
  • 61
0

For me the solution was to remove the linker flags "-Wl,-no_compact_unwind" (Catalina, Apple clang version 11.0.0 (clang-1100.0.33.17))

Fabian
  • 107
  • 1
  • 5