如何摆脱gtest编译器警告C4800(' int':强制值为bool' true'或者' false'")

时间:2015-05-22 15:12:53

标签: c++ windows-ce googletest

我继承了一些使用gtest的单元测试代码(基于WinCE的智能设备的VS2008 c ++)。当我编译单元测试时,我得到各种关于强制注入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>        ]

1 个答案:

答案 0 :(得分:0)

警告当将int放入bool类型的变量时,会给出C4800。警告C4800的documentation表示它是性能警告,因此您可能不必担心它。

如果要隐藏警告,可以使用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的文档。