【问题标题】:C4800 warning, how to find where in the source codeC4800 警告,如何在源代码中查找
【发布时间】:2013-06-05 09:18:44
【问题描述】:

当您收到这样的警告时,是否有一种聪明的方法可以在代码中找到相关位置?似乎显示的唯一行号是指标准标题,而不是实际代码。我必须补充一点,这个项目非常大,有数百个模块和 1MLOC+。

C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\utility(138): warning C4800: 'int' : forcing value to bool 'true' or 'false' (performance warning)
          C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\xtree(1804) : see reference to function template instantiation 'std::pair<_Ty1,_Ty2>::pair<std::_Tree_iterator<_Mytree>,int>(_Other1 &&,_Other2 &&,void **)' being compiled
          with
          [
              _Ty1=std::_Tree_iterator<std::_Tree_val<std::_Tree_simple_types<std::pair<const std::string,tpuTask >>>>,
              _Ty2=bool,
              _Mytree=std::_Tree_val<std::_Tree_simple_types<std::pair<const std::string,tpuTask >>>,
              _Other1=std::_Tree_iterator<std::_Tree_val<std::_Tree_simple_types<std::pair<const std::string,tpuTask >>>>,
              _Other2=int
          ]
          C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\xtree(1804) : see reference to function template instantiation 'std::pair<_Ty1,_Ty2>::pair<std::_Tree_iterator<_Mytree>,int>(_Other1 &&,_Other2 &&,void **)' being compiled
          with
          [
              _Ty1=std::_Tree_iterator<std::_Tree_val<std::_Tree_simple_types<std::pair<const std::string,tpuTask >>>>,
              _Ty2=bool,
              _Mytree=std::_Tree_val<std::_Tree_simple_types<std::pair<const std::string,tpuTask >>>,
              _Other1=std::_Tree_iterator<std::_Tree_val<std::_Tree_simple_types<std::pair<const std::string,tpuTask >>>>,
              _Other2=int
          ]
...

【问题讨论】:

  • 你最好好好看看你的“tpuTask”类。它似乎允许转换为布尔值。这几乎总是无意的,这是显示此警告的原因。指针转换是常见问题,这是将 nullptr 添加到 C++11 的一个重要原因。
  • 是的,我认为你是对的,系统 (ab) 使用一种方法将通用联合指针转换为各种数据类型,我认为这在某些 C++ 特定情况下效果不佳,例如在 STL 容器中键入实例。

标签: visual-c++ stl


【解决方案1】:

您的代码没有问题。

但不幸的是,VC 标准头文件中的代码在级别 4 中并非无警告。您只能使用编译器选项禁用该警告。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-04-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-06-12
    • 2014-01-06
    • 2013-06-17
    相关资源
    最近更新 更多