#include <charconv> #include <iostream> #include <string> #include <system_error> int main() { std::string token{"42"}; int value{}; if (const auto [p, ec] = std::from_chars(token.data(), token.data() + token.size(), value); ec == std::errc()) { std::cout << value; } }
Got a false positive "CWE-398 The scope of the variable 'value' can be reduced.cppcheck(style:variableScope)"
value's scope cannot be reduced since std::from_chars takes in value as a out-parameter. See : https://en.cppreference.com/w/cpp/utility/from_chars.
Reduced example:
int main() { int value{}; if (int s = f(value); s == 1) { return s; } }
Thanks for reporting, ticket is here: https://trac.cppcheck.net/ticket/10527
Log in to post a comment.
Got a false positive
"CWE-398 The scope of the variable 'value' can be reduced.cppcheck(style:variableScope)"
value's scope cannot be reduced since std::from_chars takes in value as a out-parameter.
See : https://en.cppreference.com/w/cpp/utility/from_chars.
Last edit: Piyush Kumar 2021-10-04
Reduced example:
Thanks for reporting, ticket is here: https://trac.cppcheck.net/ticket/10527