Found in version 2.5
When using C++17s structured binding in range based for loops cppcheck is claiming that the first variable is never assigned:
struct Pair { Pair(int first, int second) : first(first), second(second) {}; int first; int second; }; std::vector<Pair> GetPairs() { return {{0, 1}, {1, 2}}; } int main() { for (const auto& [first, second] : GetPairs()) { std::cout << first << second; } }
generates:
cppcheckWarnings.cpp:35:21: warning: Variable 'first' is not assigned a value. [unassignedVariable] for (const auto& [first, second] : GetPairs()) ^
Dropping the reference fixes the issue but in our actual use case we are passing out custom iterators
Sounds similar to this ticket: https://trac.cppcheck.net/ticket/10368
Log in to post a comment.
Found in version 2.5
When using C++17s structured binding in range based for loops cppcheck is claiming that the first variable is never assigned:
generates:
Dropping the reference fixes the issue but in our actual use case we are passing out custom iterators
Last edit: Dan Workman 2021-08-04
Sounds similar to this ticket: https://trac.cppcheck.net/ticket/10368