GoogleTest 1.7.0 `enum class` 编译错误

GoogleTest 1.7.0 `enum class` compile error

当我尝试从测试夹具引用 enum class 时,它无法编译并出现错误 ./gtest_mcp23s17.cpp:25:52: error: no type named 'HW_ADDR_6' in 'mcp23s17::HardwareAddress' TC_mcp23s17 _gpio_x(mcp23s17::HardwareAddress::HW_ADDR_6); ~~~~~~~~~~~~~~~~~~~~~~~~~~~^

但是,如果我将引用留在测试本身中(保持所有其他代码不变),它会编译无误并按您预期的那样运行测试。这是 GoogleTest 中的错误,还是就测试而言,这种情况有何不同?

测试 (通用): [编译]

TEST(Construction, WHENObjectIsConstructedTHENAddressParameterIsStored) {
    TC_mcp23s17 gpio_x(mcp23s17::HardwareAddress::HW_ADDR_6);
    EXPECT_EQ(0x4C, gpio_x.getSpiBusAddress());
}

测试夹具: [编译]

TEST_F(SPITransfer, WHENPinModeHasNotBeenCalledTHENTheCallersChipSelectPinIsHigh) {
    TC_mcp23s17 gpio_x(mcp23s17::HardwareAddress::HW_ADDR_6);
    EXPECT_EQ(HIGH, getPinLatchValue(SS));
}

测试夹具 (在夹具 class 中声明了 gpio_x): [失败]

class SPITransfer : public ::testing::Test {
  protected:
    TC_mcp23s17 gpio_x(mcp23s17::HardwareAddress::HW_ADDR_6);
    ...
}
TEST_F(SPITransfer, WHENPinModeHasNotBeenCalledTHENTheCallersChipSelectPinIsHigh) {
    EXPECT_EQ(HIGH, getPinLatchValue(SS));
}

一个class成员只能用={}初始化,不能用()初始化。所以这些都应该有效:

TC_mcp23s17 gpio_x=mcp23s17::HardwareAddress::HW_ADDR_6;
TC_mcp23s17 gpio_x{mcp23s17::HardwareAddress::HW_ADDR_6};

相当无用的错误消息是因为编译器将 () 的用法解释为表示函数声明,然后由于括号内的内容不是类型而感到困惑。