Hi, I found a false negative in Cppcheck 2.21.0 and 2.22 dev when both values from a structured binding are overwritten before either initial value is read.
Affected tool
Cppcheck 2.21.0; also reproduced with Cppcheck 2.22 dev
Affected checker
Cppcheck unreadVariable
Minimal reproducer
struct Pair { int left; int right; }; Pair make_pair(); int test() { auto [left, right] = make_pair(); left = 1; right = 2; return left + right; }
Reproduction command
cppcheck --version cppcheck --enable=style --inconclusive --std=c++17 --checkers-report=checkers.txt --template='{file}:{line}:{column}: [{id}] {message}' cppcheck-unreadvariable-fn-structured-binding.cpp
Current behavior
Cppcheck produces no unreadVariable or redundantAssignment diagnostic.
unreadVariable
redundantAssignment
Expected behavior
Cppcheck should report line 9 because the initial values assigned to left and right are overwritten before being read.
left
right
Thanks for reporting, ticket is here: https://trac.cppcheck.net/ticket/15021
Log in to post a comment.
Hi, I found a false negative in Cppcheck 2.21.0 and 2.22 dev when both values from a structured binding are overwritten before either initial value is read.
Affected tool
Cppcheck 2.21.0; also reproduced with Cppcheck 2.22 devAffected checker
Cppcheck unreadVariableMinimal reproducer
Reproduction command
Current behavior
Cppcheck produces no
unreadVariableorredundantAssignmentdiagnostic.Expected behavior
Cppcheck should report line 9 because the initial values assigned to
leftandrightare overwritten before being read.Thanks for reporting, ticket is here: https://trac.cppcheck.net/ticket/15021