#include <vector> int test(const std::vector<int>& Arr) { if (!Arr.empty() && Arr[0] == 0) return 2; if (!Arr.empty()) return Arr[0]; return 1; }
v.2.3 called with "C:\Program Files\Cppcheck\cppcheck.exe" --inconclusive --enable=all foo.cpp reports
"C:\Program Files\Cppcheck\cppcheck.exe" --inconclusive --enable=all foo.cpp
Checking foo.cpp ... foo.cpp:30:7: style: Condition '!Arr.empty()' is always false [knownConditionTrueFalse] if (!Arr.empty()) ^ foo.cpp:28:17: note: Assuming that condition 'Arr.empty()' is not redundant if (!Arr.empty() && Arr[0] == 0) ^ foo.cpp:30:7: note: Condition '!Arr.empty()' is always false if (!Arr.empty()) ^ foo.cpp:13:0: style: The function 'nullArith' is never used. [unusedFunction]
The warning disappears if const is removed from test()'s signature.
Thanks! I have created ticket https://trac.cppcheck.net/ticket/10088
Log in to post a comment.
v.2.3 called with
"C:\Program Files\Cppcheck\cppcheck.exe" --inconclusive --enable=all foo.cpp
reportsThe warning disappears if const is removed from test()'s signature.
Thanks! I have created ticket https://trac.cppcheck.net/ticket/10088