diff --git a/test/teststl.cpp b/test/teststl.cpp index 4b30cdf9b..1d0f835f0 100644 --- a/test/teststl.cpp +++ b/test/teststl.cpp @@ -646,17 +646,42 @@ private: void if_find() { + // --------------------------- + // string::find + // --------------------------- + + // error check("void f(std::string s)\n" "{\n" " if (s.find(\"ab\")) { }\n" "}\n"); ASSERT_EQUALS("[test.cpp:3]: (possible style) Suspicious condition. string::find will return 0 if the string is found at position 0. If this is what you want to check then string::compare is a faster alternative because it doesn't scan through the string.\n", errout.str()); + // ok + check("void f(std::string s)\n" + "{\n" + " if (s.find(\"ab\") != std::string::npos) { }\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); + + + // --------------------------- + // set::find + // --------------------------- + + // error check("void f(std::set s)\n" "{\n" " if (s.find(12)) { }\n" "}\n"); ASSERT_EQUALS("[test.cpp:3]: (style) Suspicious condition. The result of find is an iterator, but it is not properly checked.\n", errout.str()); + + // ok + check("void f(std::set s)\n" + "{\n" + " if (s.find(123) != s.end()) { }\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); }