我目前正在维护的 C++ 库中进行正确的错误管理。当为一些负面情况编写单元测试时(即测试正确抛出异常),单元测试套件只是用 SIGABRT 中止了。我继续寻找并尝试通过抛出更简单的异常并尝试使用各种 catch 语句来归结错误。但即使是一个包罗万象的块也无法阻止崩溃(对于 MWE,见下文)。
我的设置是这样的:我在 Mac 上使用最新的 OS X Big Sur 11.1,并安装了最新的 XCode 命令行工具。我正在使用 Homebrew 的 GCC,目前是 v10.2.0_1。
$ g++-10 -v
Using built-in specs.
COLLECT_GCC=g++-10
COLLECT_LTO_WRAPPER=/usr/local/Cellar/gcc/10.2.0_1/libexec/gcc/x86_64-apple-darwin20/10.2.0/lto-wrapper
Target: x86_64-apple-darwin20
Configured with: ../configure --build=x86_64-apple-darwin20 --prefix=/usr/local/Cellar/gcc/10.2.0_1 --libdir=/usr/local/Cellar/gcc/10.2.0_1/lib/gcc/10 --disable-nls --enable-checking=release --enable-languages=c,c++,objc,obj-c++,fortran --program-suffix=-10 --with-gmp=/usr/local/opt/gmp --with-mpfr=/usr/local/opt/mpfr --with-mpc=/usr/local/opt/libmpc --with-isl=/usr/local/opt/isl --with-system-zlib --with-pkgversion='Homebrew GCC 10.2.0_1' --with-bugurl=https://github.com/Homebrew/homebrew-core/issues --disable-multilib --with-native-system-header-dir=/usr/include --with-sysroot=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk SED=/usr/bin/sed
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 10.2.0 (Homebrew GCC 10.2.0_1)
Run Code Online (Sandbox Code Playgroud)
我还使用 Apples 系统工具链自己编译了 GCC。自编译 GCC 的输出是这样的:
$ /opt/gcc/10.2.0/bin/g++-10 -v
Using built-in …
Run Code Online (Sandbox Code Playgroud)