Hi, I found false negatives regarding the rule accessMoved involving lambda expressions.
Cppcheck should report accessMoved warnings for the following two programs because both access a std::string object after it has been moved from. However, cppcheck reports no accessMoved warning.
Case 1: moved object passed through a lambda rvalue-reference parameter
In this program, s is moved into consume, and then accessed inside a lambda that captures it by reference. This should also trigger an accessMoved warning.
Actual result
Cppcheck reports no accessMoved warning for either program.
Expected result
Cppcheck should report accessMoved warnings for the accesses to s after std::move(s).
Version: 2.21.0
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi, I found false negatives regarding the rule
accessMovedinvolving lambda expressions.Cppcheck should report
accessMovedwarnings for the following two programs because both access astd::stringobject after it has been moved from. However, cppcheck reports noaccessMovedwarning.Case 1: moved object passed through a lambda rvalue-reference parameter
In this program,
sis passed to the lambda as an rvalue reference, then moved from inside the lambda. The later accesses tosshould be reported.Case 2: moved object accessed inside a lambda capture
In this program,
sis moved intoconsume, and then accessed inside a lambda that captures it by reference. This should also trigger anaccessMovedwarning.Actual result
Cppcheck reports no
accessMovedwarning for either program.Expected result
Cppcheck should report
accessMovedwarnings for the accesses tosafterstd::move(s).Version: 2.21.0
For the first example, I'm getting two warnings:
The second example is covered by https://trac.cppcheck.net/ticket/13774