I am new to cppcheck, and was surprised to find that this code generates a warning:
#include <map> int main() { std::map<char const*, int> m{ {"a", 1} }; if (auto iter = m.find("x"); iter != m.end()) { return iter->second; } return 0; }
To reproduce the warning, use cppcheck --enable=all --std=c++17 <filename>.cpp. Using the latest git head (2a4b28c267059b5520f47f528a67f903d910f2df), I get:
cppcheck --enable=all --std=c++17 <filename>.cpp
[if-init.cpp:6]: (warning) Suspicious condition. The result of find() is an iterator, but it is not properly checked.
I tried searching for it on trac.cppcheck.net, but couldn't find anything, so I thought I should mention it here.
Thanks for reporting this bug! I created this ticket: https://trac.cppcheck.net/ticket/9176
👍
I have another potential ticket for you, but I'll create a new thread for it since it is completely unrelated to this one. :)
Log in to post a comment.
I am new to cppcheck, and was surprised to find that this code generates a warning:
To reproduce the warning, use
cppcheck --enable=all --std=c++17 <filename>.cpp. Using the latest git head (2a4b28c267059b5520f47f528a67f903d910f2df), I get:I tried searching for it on trac.cppcheck.net, but couldn't find anything, so I thought I should mention it here.
Thanks for reporting this bug! I created this ticket: https://trac.cppcheck.net/ticket/9176
👍
I have another potential ticket for you, but I'll create a new thread for it since it is completely unrelated to this one. :)