fixed #11183 (checkLibraryFunction with parameter to "std::string()") / added rudimentary tests for `CheckFunctions::checkLibraryMatchFunctions()` / added test for #10105 (#4265)
This commit is contained in:
parent
aea4fd1068
commit
22be5f29aa
|
@ -624,7 +624,19 @@ void CheckFunctions::checkLibraryMatchFunctions()
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
const std::string &functionName = mSettings->library.getFunctionName(tok);
|
const std::string &functionName = mSettings->library.getFunctionName(tok);
|
||||||
if (functionName.empty() || mSettings->library.functions.find(functionName) != mSettings->library.functions.end())
|
if (functionName.empty())
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (mSettings->library.functions.find(functionName) != mSettings->library.functions.end())
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (mSettings->library.smartPointers.find(functionName) != mSettings->library.smartPointers.end())
|
||||||
|
continue;
|
||||||
|
|
||||||
|
const Token* start = tok;
|
||||||
|
while (Token::Match(start->tokAt(-2), "%name% ::"))
|
||||||
|
start = start->tokAt(-2);
|
||||||
|
if (mSettings->library.detectContainerOrIterator(start))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
reportError(tok,
|
reportError(tok,
|
||||||
|
|
|
@ -99,6 +99,8 @@ private:
|
||||||
TEST_CASE(returnLocalStdMove5);
|
TEST_CASE(returnLocalStdMove5);
|
||||||
|
|
||||||
TEST_CASE(negativeMemoryAllocationSizeError); // #389
|
TEST_CASE(negativeMemoryAllocationSizeError); // #389
|
||||||
|
|
||||||
|
TEST_CASE(checkLibraryMatchFunctions);
|
||||||
}
|
}
|
||||||
|
|
||||||
#define check(...) check_(__FILE__, __LINE__, __VA_ARGS__)
|
#define check(...) check_(__FILE__, __LINE__, __VA_ARGS__)
|
||||||
|
@ -1769,6 +1771,51 @@ private:
|
||||||
ASSERT_EQUALS("[test.cpp:3]: (warning) Obsolete function 'alloca' called.\n"
|
ASSERT_EQUALS("[test.cpp:3]: (warning) Obsolete function 'alloca' called.\n"
|
||||||
"[test.cpp:3]: (error) Invalid alloca() argument nr 1. The value is -10 but the valid values are '0:'.\n", errout.str());
|
"[test.cpp:3]: (error) Invalid alloca() argument nr 1. The value is -10 but the valid values are '0:'.\n", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void checkLibraryMatchFunctions() {
|
||||||
|
settings.checkLibrary = true;
|
||||||
|
auto severity_old = settings.severity;
|
||||||
|
settings.severity.enable(Severity::information);
|
||||||
|
|
||||||
|
check("void f() {\n"
|
||||||
|
" lib_func();"
|
||||||
|
"}");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
|
check("void f(void* v) {\n"
|
||||||
|
" lib_func(v);"
|
||||||
|
"}");
|
||||||
|
ASSERT_EQUALS("[test.cpp:2]: (information) --check-library: There is no matching configuration for function lib_func()\n", errout.str());
|
||||||
|
|
||||||
|
// #10105
|
||||||
|
check("class TestFixture {\n"
|
||||||
|
"protected:\n"
|
||||||
|
" bool prepareTest(const char testname[]);\n"
|
||||||
|
"};\n"
|
||||||
|
"\n"
|
||||||
|
"class TestMemleak : private TestFixture {\n"
|
||||||
|
" void run() {\n"
|
||||||
|
" do { prepareTest(\"testFunctionReturnType\"); } while (false);\n"
|
||||||
|
" }\n"
|
||||||
|
"\n"
|
||||||
|
" void testFunctionReturnType() {\n"
|
||||||
|
" }\n"
|
||||||
|
"};");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
|
// #11183
|
||||||
|
check("#include <string>\n"
|
||||||
|
"\n"
|
||||||
|
"extern void cb(const std::string&);\n"
|
||||||
|
"\n"
|
||||||
|
"void f() {\n"
|
||||||
|
" cb(std::string(\"\"));\n"
|
||||||
|
"}");
|
||||||
|
TODO_ASSERT_EQUALS("", "[test.cpp:6]: (information) --check-library: There is no matching configuration for function cb()\n", errout.str());
|
||||||
|
|
||||||
|
settings.severity = severity_old;
|
||||||
|
settings.checkLibrary = false;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
REGISTER_TEST(TestFunctions)
|
REGISTER_TEST(TestFunctions)
|
||||||
|
|
Loading…
Reference in New Issue