Fix ticket #426 (Problem with include)

http://sourceforge.net/apps/trac/cppcheck/ticket/426
This commit is contained in:
Reijo Tomperi 2009-06-20 23:13:19 +03:00
parent a5af858253
commit ac6e7b40e5
3 changed files with 65 additions and 7 deletions

View File

@ -441,11 +441,6 @@ void CheckClass::privateFunctions()
{
const std::string &classname = tok1->next()->str();
// The class implementation must be available..
const std::string classconstructor(classname + " :: " + classname);
if (tok1->fileIndex() > 0 && !Token::findmatch(_tokenizer->tokens(), classconstructor.c_str()))
continue;
// Get private functions..
std::list<const Token *> FuncList;
FuncList.clear();

View File

@ -42,7 +42,19 @@ public:
/**
* Tokenize code
* @param code input stream for code
* @param code input stream for code, e.g.
* #file "p.h"
* class Foo
* {
* private:
* void Bar();
* };
*
* #endfile
* void Foo::Bar()
* {
* }
*
* @param FileName The filename
* @return false if Source code contains syntax errors
*/
@ -50,7 +62,7 @@ public:
/**
* Create tokens from code.
* @param code input stream for code
* @param code input stream for code, same as what tokenize()
*/
void createTokens(std::istream &code);

View File

@ -82,6 +82,57 @@ private:
"{ }\n");
ASSERT_EQUALS("[test.cpp:4]: (style) Unused private function 'Fred::f'\n", errout.str());
check("#file \"p.h\"\n"
"class Fred\n"
"{\n"
"private:\n"
" unsigned int f();\n"
"public:\n"
" Fred();\n"
"};\n"
"\n"
"#endfile\n"
"Fred::Fred()\n"
"{ }\n"
"\n"
"unsigned int Fred::f()\n"
"{ }\n");
ASSERT_EQUALS("[p.h:4]: (style) Unused private function 'Fred::f'\n", errout.str());
check("#file \"p.h\"\n"
"class Fred\n"
"{\n"
"private:\n"
"void f();\n"
"};\n"
"\n"
"\n"
"#endfile\n"
"\n"
"void Fred::f()\n"
"{\n"
"}\n"
"\n");
ASSERT_EQUALS("[p.h:4]: (style) Unused private function 'Fred::f'\n", errout.str());
// Don't warn about include files which implementation we don't see
check("#file \"p.h\"\n"
"class Fred\n"
"{\n"
"private:\n"
"void f();\n"
"void g() {}\n"
"};\n"
"\n"
"#endfile\n"
"\n"
"int main()\n"
"{\n"
"}\n"
"\n");
ASSERT_EQUALS("", errout.str());
}