the following minimal example code gives the warning:
"Variable 'lock' is assigned a value that is never used CppCheck(unreadVariable)" warning.
In my opinion this is a false positive, as this is a valid RAII usage of a mutex lock guard.
#include<mutex>std::mutexmutex;std::lock_guard<std::mutex>lock_raii(){returnstd::lock_guard<std::mutex>(mutex);}voidtest(){{autolock=lock_raii();// THIS LINE GIVES THE WARNING// some protected code}}
What do you think?
Regards,
Frank
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hello,
the following minimal example code gives the warning:
"Variable 'lock' is assigned a value that is never used CppCheck(unreadVariable)" warning.
In my opinion this is a false positive, as this is a valid RAII usage of a mutex lock guard.
What do you think?
Regards,
Frank
Thanks for reporting this. yes of course it's a false positive. I have created ticket https://trac.cppcheck.net/ticket/10505