Hi,
the following code results in a false positive (tested with 2.15 dev from 2024-07-17):
#include <string> void foo(std::string bar) { auto lambda = [ bar {std::move(bar)} ]() { std::string bar2 = std::move(bar); }; }
test.cxx:5:34: warning: Access of moved variable 'bar'. [accessMoved] std::string bar2 = std::move(bar); ^ test.cxx:4:24: note: Calling std::move(bar) auto lambda = [ bar {std::move(bar)} ]() { ^ test.cxx:5:34: note: Access of moved variable 'bar'. std::string bar2 = std::move(bar); ^
Changing the move capture to the syntax
auto lambda = [ bar = std::move(bar) ]() {
makes the warning go away.
-Frank
Thanks for reporting, ticket is here: https://trac.cppcheck.net/ticket/12949
Log in to post a comment.
Hi,
the following code results in a false positive (tested with 2.15 dev from 2024-07-17):
Changing the move capture to the syntax
makes the warning go away.
-Frank
Last edit: Frank Winklmeier 2024-07-19
Thanks for reporting, ticket is here: https://trac.cppcheck.net/ticket/12949