c++ - 我怎样才能摆脱 gtest 编译器警告 C4800 ('int' : forcing value to bool 'true' or 'false' ")

标签 c++ windows-ce googletest

我继承了一些使用gtest的单元测试代码(VS2008 c++ for a WinCE-based smart device)。当我编译单元测试时,我收到关于强制将 int 转换为 bool 的各种 C4800 警告。奇怪的是,生成警告的模块中唯一的 gtest 调用是 EXPECT_STREQ。

这是 gtest 中的一个(小)错误吗,它以一种混淆 VS2008/WinCE 的方式执行 EXPECT_STREQ?

我们正在使用 gtest 1.6 版,有谁知道 1.7 版是否适用于 WinCE?

==============

1>C:\googletest\include\gtest/internal/gtest-port.h(1031) : warning C4800: 'int' : forcing value to bool 'true' or 'false' (performance warning)
1>        C:\googletest\include\gtest/internal/gtest-param-util.h(321) : see reference to function template instantiation 'Derived *testing::internal::CheckedDowncastToActualType<const testing::internal::ValuesInIteratorRangeGenerator<T>::Iterator,const testing::internal::ParamIteratorInterface<T>>(Base *)' being compiled
1>        with
1>        [
1>            Derived=const testing::internal::ValuesInIteratorRangeGenerator<ParamType>::Iterator,
1>            T=ParamType,
1>            Base=const testing::internal::ParamIteratorInterface<bool>
1>        ]
1>        C:\googletest\include\gtest/internal/gtest-param-util.h(314) : while compiling class template member function 'bool testing::internal::ValuesInIteratorRangeGenerator<T>::Iterator::Equals(const testing::internal::ParamIteratorInterface<T> &) const'
1>        with
1>        [
1>            T=ParamType
1>        ]
1>        C:\googletest\include\gtest/internal/gtest-param-util.h(276) : see reference to class template instantiation 'testing::internal::ValuesInIteratorRangeGenerator<T>::Iterator' being compiled
1>        with
1>        [
1>            T=ParamType
1>        ]
1>        C:\googletest\include\gtest/internal/gtest-param-util.h(275) : while compiling class template member function 'testing::internal::ParamIteratorInterface<T> *testing::internal::ValuesInIteratorRangeGenerator<T>::Begin(void) const'
1>        with
1>        [
1>            T=bool
1>        ]
1>        C:\googletest\include\gtest/gtest-param-test.h(314) : see reference to class template instantiation 'testing::internal::ValuesInIteratorRangeGenerator<T>' being compiled
1>        with
1>        [
1>            T=ParamType
1>        ]
1>        C:\googletest\include\gtest/gtest-param-test.h(319) : see reference to function template instantiation 'testing::internal::ParamGenerator<T> testing::ValuesIn<const T*>(ForwardIterator,ForwardIterator)' being compiled
1>        with
1>        [
1>            T=bool,
1>            ForwardIterator=const bool *
1>        ]
1>        C:\googletest\include\gtest/internal/gtest-param-util-generated.h(99) : see reference to function template instantiation 'testing::internal::ParamGenerator<T> testing::ValuesIn<T,2>(const T (&)[2])' being compiled
1>        with
1>        [
1>            T=bool
1>        ]
1>        C:\googletest\include\gtest/gtest-param-test.h(1221) : see reference to function template instantiation 'testing::internal::ValueArray2<T1,T2>::operator testing::internal::ParamGenerator<T>(void) const<bool>' being compiled
1>        with
1>        [
1>            T1=bool,
1>            T2=bool,
1>            T=bool
1>        ]

最佳答案

当将 int 放入 bool 类型的变量中时,会出现警告 C4800。 documentation对于警告 C4800 指出这是一个性能警告,因此您可能不必担心它。

如果你想隐藏警告,你可以使用 MSVC 的 #pragma warning(disable:4800) 来禁用警告。

所以它看起来像这样

#pragma warning(disable:4800) //Disable the warning

... // Code that gives warning here

#pragma warning(default:4800) //Stop suppressing the warning

您可以查看#pragma warning 的文档here .

关于c++ - 我怎样才能摆脱 gtest 编译器警告 C4800 ('int' : forcing value to bool 'true' or 'false' "),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30400263/

相关文章:

c++ - 在字符串字段中查找字符串的索引

c++ - 无法将矩阵的值添加到节点三的子节点

c++ - 本地 CGEventRef 是否被视为指针?

c++ - 如何从 LONGLONG 转换为类 _variant_t?

c# - 无法在 Windows CE 上将字体更改为 "Arial"

c++ - 这是防止 gtest (C++) 捕获异常和段错误的方法吗?

c++ - 重构指向某种形式模板的函数指针

c++ - 哪个文件在 Windows Embedded Compact 7.0 上配置缓存?

c++ -/usr/bin/ld : cannot find -lgmock on ubuntu while running gmock program

c++ - 如何使用谷歌测试测试实现接口(interface)的不同类/结构?