Hi, I found a false negative regarding the rule accessMoved.
Cppcheck reports accessMoved when a moved std::string declared through decltype(std::string{"test"}) is accessed directly. However, if that moved-from object is first queried with empty(), cppcheck misses the later access.
Here, decltype(std::string{"test"}) is std::string. The object s is moved into n, and then s is accessed by s.empty() and by std::cout << s.
If the if (s.empty()) block is removed, cppcheck reports accessMoved for the stream insertion. A plain std::string s version also reports accessMoved, even with the empty() call. The warning is missed for the combination of the decltype(std::string{"test"}) declaration and the empty() query before the later access.
Actual result
Cppcheck reports no accessMoved warning.
Expected result
Cppcheck should report accessMoved for the access to s after std::move(s).
Hi, I found a false negative regarding the rule
accessMoved.Cppcheck reports
accessMovedwhen a movedstd::stringdeclared throughdecltype(std::string{"test"})is accessed directly. However, if that moved-from object is first queried withempty(), cppcheck misses the later access.Here,
decltype(std::string{"test"})isstd::string. The objectsis moved inton, and thensis accessed bys.empty()and bystd::cout << s.If the
if (s.empty())block is removed, cppcheck reportsaccessMovedfor the stream insertion. A plainstd::string sversion also reportsaccessMoved, even with theempty()call. The warning is missed for the combination of thedecltype(std::string{"test"})declaration and theempty()query before the later access.Actual result
Cppcheck reports no
accessMovedwarning.Expected result
Cppcheck should report
accessMovedfor the access tosafterstd::move(s).Verification
The issue was reproduced with:
Version: 2.21.0
I'm getting a warning. Are you passing
--inconclusive?