Reverted fix for string::size. Ticket: #2756
This commit is contained in:
parent
c0bb0b6dab
commit
9e97da8a57
|
@ -827,7 +827,7 @@ bool CheckStl::isStlContainer(unsigned int varid)
|
||||||
type = type->next()->next();
|
type = type->next()->next();
|
||||||
|
|
||||||
// all possible stl containers
|
// all possible stl containers
|
||||||
static const char STL_CONTAINER_LIST[] = "basic_string|bitset|deque|list|map|multimap|multiset|priority_queue|queue|set|stack|hash_map|hash_multimap|hash_set|vector";
|
static const char STL_CONTAINER_LIST[] = "bitset|deque|list|map|multimap|multiset|priority_queue|queue|set|stack|hash_map|hash_multimap|hash_set|vector";
|
||||||
|
|
||||||
// container template string
|
// container template string
|
||||||
const std::string checkStr(std::string(STL_CONTAINER_LIST) + " <");
|
const std::string checkStr(std::string(STL_CONTAINER_LIST) + " <");
|
||||||
|
@ -835,9 +835,6 @@ bool CheckStl::isStlContainer(unsigned int varid)
|
||||||
// check if it's an stl template
|
// check if it's an stl template
|
||||||
if (Token::Match(type, checkStr.c_str()))
|
if (Token::Match(type, checkStr.c_str()))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
if (Token::Match(type, "string|wstring"))
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|
182
test/teststl.cpp
182
test/teststl.cpp
|
@ -91,8 +91,6 @@ private:
|
||||||
|
|
||||||
TEST_CASE(size1);
|
TEST_CASE(size1);
|
||||||
TEST_CASE(size2);
|
TEST_CASE(size2);
|
||||||
TEST_CASE(size3); // ticket #2757
|
|
||||||
TEST_CASE(size4); // ticket #2757
|
|
||||||
|
|
||||||
// Redundant conditions..
|
// Redundant conditions..
|
||||||
// if (ints.find(123) != ints.end()) ints.remove(123);
|
// if (ints.find(123) != ints.end()) ints.remove(123);
|
||||||
|
@ -1181,186 +1179,6 @@ private:
|
||||||
ASSERT_EQUALS("[test.cpp:10]: (performance) Possible inefficient checking for 'x' emptiness.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:10]: (performance) Possible inefficient checking for 'x' emptiness.\n", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void size3() // ticket #2757
|
|
||||||
{
|
|
||||||
check("struct Fred {\n"
|
|
||||||
" void foo();\n"
|
|
||||||
" std::basic_string<TCHAR> x;\n"
|
|
||||||
"};\n"
|
|
||||||
"void Fred::foo()\n"
|
|
||||||
"{\n"
|
|
||||||
" if (x.size() == 0) {}\n"
|
|
||||||
"}\n");
|
|
||||||
ASSERT_EQUALS("[test.cpp:7]: (performance) Possible inefficient checking for 'x' emptiness.\n", errout.str());
|
|
||||||
|
|
||||||
check("std::basic_string<TCHAR> x;\n"
|
|
||||||
"void f()\n"
|
|
||||||
"{\n"
|
|
||||||
" if (x.size() == 0) {}\n"
|
|
||||||
"}\n");
|
|
||||||
ASSERT_EQUALS("[test.cpp:4]: (performance) Possible inefficient checking for 'x' emptiness.\n", errout.str());
|
|
||||||
|
|
||||||
check("void f()\n"
|
|
||||||
"{\n"
|
|
||||||
" std::basic_string<TCHAR> x;\n"
|
|
||||||
" if (x.size() == 0) {}\n"
|
|
||||||
"}\n");
|
|
||||||
ASSERT_EQUALS("[test.cpp:4]: (performance) Possible inefficient checking for 'x' emptiness.\n", errout.str());
|
|
||||||
|
|
||||||
check("void f()\n"
|
|
||||||
"{\n"
|
|
||||||
" std::basic_string<TCHAR> x;\n"
|
|
||||||
" if (0 == x.size()) {}\n"
|
|
||||||
"}\n");
|
|
||||||
ASSERT_EQUALS("[test.cpp:4]: (performance) Possible inefficient checking for 'x' emptiness.\n", errout.str());
|
|
||||||
|
|
||||||
check("void f()\n"
|
|
||||||
"{\n"
|
|
||||||
" std::basic_string<TCHAR> x;\n"
|
|
||||||
" if (x.size() != 0) {}\n"
|
|
||||||
"}\n");
|
|
||||||
ASSERT_EQUALS("[test.cpp:4]: (performance) Possible inefficient checking for 'x' emptiness.\n", errout.str());
|
|
||||||
|
|
||||||
check("void f()\n"
|
|
||||||
"{\n"
|
|
||||||
" std::basic_string<TCHAR> x;\n"
|
|
||||||
" if (0 != x.size()) {}\n"
|
|
||||||
"}\n");
|
|
||||||
ASSERT_EQUALS("[test.cpp:4]: (performance) Possible inefficient checking for 'x' emptiness.\n", errout.str());
|
|
||||||
|
|
||||||
check("void f()\n"
|
|
||||||
"{\n"
|
|
||||||
" std::basic_string<TCHAR> x;\n"
|
|
||||||
" if (x.size() > 0) {}\n"
|
|
||||||
"}\n");
|
|
||||||
ASSERT_EQUALS("[test.cpp:4]: (performance) Possible inefficient checking for 'x' emptiness.\n", errout.str());
|
|
||||||
|
|
||||||
check("void f()\n"
|
|
||||||
"{\n"
|
|
||||||
" std::basic_string<TCHAR> x;\n"
|
|
||||||
" if (0 < x.size()) {}\n"
|
|
||||||
"}\n");
|
|
||||||
ASSERT_EQUALS("[test.cpp:4]: (performance) Possible inefficient checking for 'x' emptiness.\n", errout.str());
|
|
||||||
|
|
||||||
check("void f()\n"
|
|
||||||
"{\n"
|
|
||||||
" std::basic_string<TCHAR> x;\n"
|
|
||||||
" if (x.size()) {}\n"
|
|
||||||
"}\n");
|
|
||||||
ASSERT_EQUALS("[test.cpp:4]: (performance) Possible inefficient checking for 'x' emptiness.\n", errout.str());
|
|
||||||
|
|
||||||
check("void f()\n"
|
|
||||||
"{\n"
|
|
||||||
" std::basic_string<TCHAR> x;\n"
|
|
||||||
" if (!x.size()) {}\n"
|
|
||||||
"}\n");
|
|
||||||
ASSERT_EQUALS("[test.cpp:4]: (performance) Possible inefficient checking for 'x' emptiness.\n", errout.str());
|
|
||||||
|
|
||||||
check("void f()\n"
|
|
||||||
"{\n"
|
|
||||||
" std::basic_string<TCHAR> x;\n"
|
|
||||||
" fun(x.size());\n"
|
|
||||||
"}\n");
|
|
||||||
ASSERT_EQUALS("", errout.str());
|
|
||||||
|
|
||||||
check("void f()\n"
|
|
||||||
"{\n"
|
|
||||||
" std::basic_string<TCHAR> x;\n"
|
|
||||||
" fun(!x.size());\n"
|
|
||||||
"}\n");
|
|
||||||
ASSERT_EQUALS("", errout.str());
|
|
||||||
}
|
|
||||||
|
|
||||||
void size4() // ticket #2757
|
|
||||||
{
|
|
||||||
check("struct Fred {\n"
|
|
||||||
" void foo();\n"
|
|
||||||
" std::string x;\n"
|
|
||||||
"};\n"
|
|
||||||
"void Fred::foo()\n"
|
|
||||||
"{\n"
|
|
||||||
" if (x.size() == 0) {}\n"
|
|
||||||
"}\n");
|
|
||||||
ASSERT_EQUALS("[test.cpp:7]: (performance) Possible inefficient checking for 'x' emptiness.\n", errout.str());
|
|
||||||
|
|
||||||
check("std::string x;\n"
|
|
||||||
"void f()\n"
|
|
||||||
"{\n"
|
|
||||||
" if (x.size() == 0) {}\n"
|
|
||||||
"}\n");
|
|
||||||
ASSERT_EQUALS("[test.cpp:4]: (performance) Possible inefficient checking for 'x' emptiness.\n", errout.str());
|
|
||||||
|
|
||||||
check("void f()\n"
|
|
||||||
"{\n"
|
|
||||||
" std::string x;\n"
|
|
||||||
" if (x.size() == 0) {}\n"
|
|
||||||
"}\n");
|
|
||||||
ASSERT_EQUALS("[test.cpp:4]: (performance) Possible inefficient checking for 'x' emptiness.\n", errout.str());
|
|
||||||
|
|
||||||
check("void f()\n"
|
|
||||||
"{\n"
|
|
||||||
" std::string x;\n"
|
|
||||||
" if (0 == x.size()) {}\n"
|
|
||||||
"}\n");
|
|
||||||
ASSERT_EQUALS("[test.cpp:4]: (performance) Possible inefficient checking for 'x' emptiness.\n", errout.str());
|
|
||||||
|
|
||||||
check("void f()\n"
|
|
||||||
"{\n"
|
|
||||||
" std::string x;\n"
|
|
||||||
" if (x.size() != 0) {}\n"
|
|
||||||
"}\n");
|
|
||||||
ASSERT_EQUALS("[test.cpp:4]: (performance) Possible inefficient checking for 'x' emptiness.\n", errout.str());
|
|
||||||
|
|
||||||
check("void f()\n"
|
|
||||||
"{\n"
|
|
||||||
" std::string x;\n"
|
|
||||||
" if (0 != x.size()) {}\n"
|
|
||||||
"}\n");
|
|
||||||
ASSERT_EQUALS("[test.cpp:4]: (performance) Possible inefficient checking for 'x' emptiness.\n", errout.str());
|
|
||||||
|
|
||||||
check("void f()\n"
|
|
||||||
"{\n"
|
|
||||||
" std::string x;\n"
|
|
||||||
" if (x.size() > 0) {}\n"
|
|
||||||
"}\n");
|
|
||||||
ASSERT_EQUALS("[test.cpp:4]: (performance) Possible inefficient checking for 'x' emptiness.\n", errout.str());
|
|
||||||
|
|
||||||
check("void f()\n"
|
|
||||||
"{\n"
|
|
||||||
" std::string x;\n"
|
|
||||||
" if (0 < x.size()) {}\n"
|
|
||||||
"}\n");
|
|
||||||
ASSERT_EQUALS("[test.cpp:4]: (performance) Possible inefficient checking for 'x' emptiness.\n", errout.str());
|
|
||||||
|
|
||||||
check("void f()\n"
|
|
||||||
"{\n"
|
|
||||||
" std::string x;\n"
|
|
||||||
" if (x.size()) {}\n"
|
|
||||||
"}\n");
|
|
||||||
ASSERT_EQUALS("[test.cpp:4]: (performance) Possible inefficient checking for 'x' emptiness.\n", errout.str());
|
|
||||||
|
|
||||||
check("void f()\n"
|
|
||||||
"{\n"
|
|
||||||
" std::string x;\n"
|
|
||||||
" if (!x.size()) {}\n"
|
|
||||||
"}\n");
|
|
||||||
ASSERT_EQUALS("[test.cpp:4]: (performance) Possible inefficient checking for 'x' emptiness.\n", errout.str());
|
|
||||||
|
|
||||||
check("void f()\n"
|
|
||||||
"{\n"
|
|
||||||
" std::string x;\n"
|
|
||||||
" fun(x.size());\n"
|
|
||||||
"}\n");
|
|
||||||
ASSERT_EQUALS("", errout.str());
|
|
||||||
|
|
||||||
check("void f()\n"
|
|
||||||
"{\n"
|
|
||||||
" std::string x;\n"
|
|
||||||
" fun(!x.size());\n"
|
|
||||||
"}\n");
|
|
||||||
ASSERT_EQUALS("", errout.str());
|
|
||||||
}
|
|
||||||
|
|
||||||
void redundantCondition2()
|
void redundantCondition2()
|
||||||
{
|
{
|
||||||
check("void f()\n"
|
check("void f()\n"
|
||||||
|
|
Loading…
Reference in New Issue