Symbol database: Bug fix

This commit is contained in:
Robert Reif 2010-11-03 20:33:07 +01:00 committed by Daniel Marjamäki
parent c0100bac94
commit cf0403434d
2 changed files with 53 additions and 8 deletions

View File

@ -446,8 +446,20 @@ void CheckClass::createSymbolDatabase()
const Token *argStart = 0;
// function?
if (tok->previous()->str() == "::" && isFunction(tok, &funcStart, &argStart))
addFunction(&info, &tok);
if (isFunction(tok, &funcStart, &argStart))
{
// has body?
if (Token::Match(argStart->link(), ") const| {|:"))
{
// class function
if (tok->previous()->str() == "::")
addFunction(&info, &tok);
// regular function
else
addNewFunction(&info, &tok);
}
}
}
}
@ -460,13 +472,17 @@ void CheckClass::createSymbolDatabase()
// function?
if (isFunction(tok, &funcStart, &argStart))
{
// class function
if (tok->previous()->str() == "::")
addFunction(&info, &tok);
// has body?
if (Token::Match(argStart->link(), ") const| {|:"))
{
// class function
if (tok->previous() && tok->previous()->str() == "::")
addFunction(&info, &tok);
// regular function
else
addNewFunction(&info, &tok);
// regular function
else
addNewFunction(&info, &tok);
}
}
}
}

View File

@ -165,6 +165,7 @@ private:
TEST_CASE(symboldatabase1);
TEST_CASE(symboldatabase2);
TEST_CASE(symboldatabase3); // ticket #2000
TEST_CASE(symboldatabase4);
}
// Check the operator Equal
@ -4739,6 +4740,34 @@ private:
"};\n");
ASSERT_EQUALS("", errout.str());
}
void symboldatabase4()
{
checkConst("static void function_declaration_before(void) __attribute__((__used__));\n"
"static void function_declaration_before(void) {}\n"
"static void function_declaration_after(void) {}\n"
"static void function_declaration_after(void) __attribute__((__used__));\n");
ASSERT_EQUALS("", errout.str());
checkConst("main(int argc, char *argv[]) { }\n");
ASSERT_EQUALS("", errout.str());
checkConst("namespace boost {\n"
" std::locale generate_locale()\n"
" {\n"
" return std::locale();\n"
" }\n"
"}\n");
ASSERT_EQUALS("", errout.str());
checkConst("namespace X {\n"
" static void function_declaration_before(void) __attribute__((__used__));\n"
" static void function_declaration_before(void) {}\n"
" static void function_declaration_after(void) {}\n"
" static void function_declaration_after(void) __attribute__((__used__));\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}
};
REGISTER_TEST(TestClass)