gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-04 13:33:56 25 4
gpt4 key购买 nike

我继承了一些使用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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com