误报警告PVS Studio:V808类型的对象是创建但未使用的
False positive warning PVS Studio: V808 object of type was created but was not utilized
pvs Studio 6.17(Windows 7,64bit,vs2015)似乎在下面的代码上发出了错误的警告。创建了" unordered_map"类型的" V808'状态"对象的警告。具有unordered_map初始化的原始代码,并使用几个QStringLiteral键值进行初始化。仅使用STL的简化版本看起来像:
#include <string>
#include <unordered_map>
#include <iostream>
// Simplified analogue of QStringLiteral
#define StringLiteral(str) ([]() { return std::string{str}; }())
int main()
{
const std::unordered_map<std::string, int> statuses{
{ StringLiteral("aaa"), 1 },
{ StringLiteral("bbb"), 2 },
{ StringLiteral("ccc"), 3 }
};
auto iter = statuses.find("aaa");
if (iter != statuses.cend())
std::cout << iter->first << " has status: " << iter->second << std::endl;
return 0;
}
奇怪的是,当使用lambda中返回值的通用初始化时,就会产生V808。如果使用构造函数函数语法,则不会显示警告。
另一个错误的案例产生V808:
const std::unordered_map<int, std::function<void(int, int)>> functions{
{ 0, [](int a, int b) {} },
{ 1, [](int a, int b) {} },
};
const auto it = functions.find(0);
if (it != functions.cend() && it->second)
it->second(1, 2);
在这里,如果使用一个参数lambdas创建映射 - 无V808,它带有2个或更多的agruments。
参考:
- https://www.viva64.com/en/w/v808/
是知道的问题吗?
请不要创建此类类型的问题。Stackoverflow用户对类似问题反复评论。
- 实际上没有什么可回答的。这只是对工作不足的描述,而不是一个问题。错误报告和功能请求在堆栈溢出上不在主题上。我想请您在类似情况下写我们的支持。
- 请检查该分析仪会产生警告的书面合成示例。我无法通过检查已发布的代码来复制误报。我猜该代码包含一些使分析仪感到困惑的东西。或分析仪可能是正确的,例如,如果使用情况在不活动的构造#if ...#endif。
相关文章:
- 如何为模板化对象创建模板向量?VS正在投掷C3203
- 具有包含其他对象的类的对象创建顺序
- 为什么我们再次从结构对象创建结构变量?
- 将对象创建为全局/静态对象会崩溃,而本地对象不会崩溃
- 如何创建一个对象创建函数,该函数将由与其关联的名称调用?
- 如何为自定义模板对象创建专门的函数模板
- 对象创建错误的C++矢量
- 如何为Python Swigged C++对象创建和分配回调函数
- 在 C++ 中为 C 样式对象创建一个透明包装类
- 此类模板的对象创建如何工作?
- C++ 中的对象创建类型有什么区别?
- 未知大小的数组作为类成员,用于在运行时(对象创建时间)创建数组的对象
- 如何仅通过父类对象限制对象创建
- 在正确性或良好的代码结构方面,这种动态对象创建看起来如何
- 无法将类对象创建为另一个类的成员
- 如何从现有基类对象创建派生类对象
- 在 DTor 之前删除的静态对象创建的线程?
- C++:定义多个构造函数时的对象创建/销毁序列
- 从对象创建矢量包装器,该对象只允许使用索引访问向量
- 是否可以为CPP中的对象创建一组指针