gtest 意外转换

gtest unexpected conversion

我正在测试我的功能是否正确运行

bool Core::IsMeta(void)
{
  return mProc->GetCode(mPC)->Meta;
}

使用说明

EXPECT_EQ(true,CC->IsMeta()); // The instruction pointed to is meta
EXPECT_EQ(false,CC1->IsMeta()); // The instruction pointed to is NOT meta

测试 运行 OK,但两个测试的行为不同:'true' 案例编译正常,'false' 案例出现警告

In file included from /... ./build/gtest/src/gtest/include/gtest/gtest.h:1929:0, from /... .cpp:1: /... .cpp: In member function ‘virtual void ... ::TestBody()’: /... /build/gtest/src/gtest/include/gtest/internal/gtest-internal.h:133:55: warning: converting ‘false’ to pointer type for argument 1 of ‘char testing::internal::IsNullLiteralHelper(testing::internal::Secret*)’ [-Wconversion-null] (sizeof(::testing::internal::IsNullLiteralHelper(x)) == 1) ^

为什么gtest要将'false'转换为指针?为什么不 'true'? 我想念什么吗?

对于布尔值,您需要使用 EXPECT_TRUE()EXPECT_FALSE() 而不是 EXPECT_EQ

问题不在于 gtest,它实际上是一个 gcc 错误,如所述here