C++11 中带有 HippoMocks 成员的 gtest 派生 类 的编译错误松散抛出说明符

Compilation error looser throw specifier for gtest derived classes with HippoMocks member in C++11

我在使用 C++11 编译源自 google 测试的 testing::Test 的测试用例时出现以下错误。如果我的派生 class 有 HippoMock::MockRepository 成员,将抛出以下错误。

looser throw specifier for virtual MyTestClass::~MyTestClass noexcept(false) error overriding 'virtual testing::Test::~Test() noexcept(true)'

报告此错误是因为 HippoMock::MockRespository 析构函数抛出异常并定义为 noexcept(false),但是 google 测试析构函数定义为 'virtual testing::Test::~Test()'

分辨率:

  1. 将所有派生的析构函数标记为 noexcept(false)。然而这是 不可行,可能会导致崩溃,因为 HippoMock::MockRepository 抛出 来自析构函数的异常。
  2. 声明 google 测试 testing::Test::~Test() noexcept(false)。然而 我真的不知道后果,还有我们使用的新代码 google 模拟。

请注意,由于遗留代码包含大量 HippoMocks 代码,因此无法将所有代码替换为 Google Mock。较新的代码也使用 google mock.

我只是想知道, 定义 gtest testing::Test::~Test() noexcept(false) 的后果是什么?

已通过更新到最新版本的 HippoMocks 解决此问题 https://github.com/dascandy/hippomocks.