PVS Studio 6.17 (Windows 7, 64Bit, VS2017, C++-03) seems to give a wrong warning on following reduced code
#include <stack>
#include <string>
#include <vector>
bool fred(const std::string &x)
{
return x == "ab";
}
std::vector<std::string> bar(std::stack<std::string> & s)
{
std::vector<std::string> v;
const std::string rhs(s.top()); // V821 Decreased perfomance. The 'rhs' variable can be constructed in a lower level scope.
s.pop();
const std::string lhs(s.top());
s.pop();
if (fred(lhs))
{
v.push_back(rhs);
}
return v;
}
The warning from PVS studio is
V821 Decreased perfomance. The 'rhs' variable can be constructed in a lower level scope.
Since s
is a std::stack
-type, and the corresponding algorithm requires that the rhs
-element is popped from the stack, it looks like PVS-Studio is wrong. Did i miss something?
By the way:
There is a typo in PVS Studio message:
perfomance->performance
Reference