@@ -99,6 +99,8 @@ class TestFunctions : public TestFixture {
9999 TEST_CASE (returnLocalStdMove5);
100100
101101 TEST_CASE (negativeMemoryAllocationSizeError); // #389
102+
103+ TEST_CASE (checkLibraryMatchFunctions);
102104 }
103105
104106#define check (...) check_(__FILE__, __LINE__, __VA_ARGS__)
@@ -1769,6 +1771,51 @@ class TestFunctions : public TestFixture {
17691771 ASSERT_EQUALS (" [test.cpp:3]: (warning) Obsolete function 'alloca' called.\n "
17701772 " [test.cpp:3]: (error) Invalid alloca() argument nr 1. The value is -10 but the valid values are '0:'.\n " , errout.str ());
17711773 }
1774+
1775+ void checkLibraryMatchFunctions () {
1776+ settings.checkLibrary = true ;
1777+ auto severity_old = settings.severity ;
1778+ settings.severity .enable (Severity::information);
1779+
1780+ check (" void f() {\n "
1781+ " lib_func();"
1782+ " }" );
1783+ ASSERT_EQUALS (" " , errout.str ());
1784+
1785+ check (" void f(void* v) {\n "
1786+ " lib_func(v);"
1787+ " }" );
1788+ ASSERT_EQUALS (" [test.cpp:2]: (information) --check-library: There is no matching configuration for function lib_func()\n " , errout.str ());
1789+
1790+ // #10105
1791+ check (" class TestFixture {\n "
1792+ " protected:\n "
1793+ " bool prepareTest(const char testname[]);\n "
1794+ " };\n "
1795+ " \n "
1796+ " class TestMemleak : private TestFixture {\n "
1797+ " void run() {\n "
1798+ " do { prepareTest(\" testFunctionReturnType\" ); } while (false);\n "
1799+ " }\n "
1800+ " \n "
1801+ " void testFunctionReturnType() {\n "
1802+ " }\n "
1803+ " };" );
1804+ ASSERT_EQUALS (" " , errout.str ());
1805+
1806+ // #11183
1807+ check (" #include <string>\n "
1808+ " \n "
1809+ " extern void cb(const std::string&);\n "
1810+ " \n "
1811+ " void f() {\n "
1812+ " cb(std::string(\"\" ));\n "
1813+ " }" );
1814+ TODO_ASSERT_EQUALS (" " , " [test.cpp:6]: (information) --check-library: There is no matching configuration for function cb()\n " , errout.str ());
1815+
1816+ settings.severity = severity_old;
1817+ settings.checkLibrary = false ;
1818+ }
17721819};
17731820
17741821REGISTER_TEST (TestFunctions)
0 commit comments