Symbol database: fixed problems with namespaces. Ticket: #1895

This commit is contained in:
Robert Reif 2010-08-16 18:55:39 +02:00 committed by Daniel Marjamäki
parent 85acb005a2
commit cc079462dd
2 changed files with 32 additions and 4 deletions

View File

@ -70,10 +70,17 @@ void CheckClass::createSymbolDatabase()
new_info->nest = info;
new_info->access = tok->str() == "struct" ? Public : Private;
new_info->numConstructors = 0;
new_info->getVarList();
// goto initial '{'
const Token *tok2 = initBaseInfo(new_info, tok);
const Token *tok2 = tok->tokAt(2);
// only create variable list and base list if not namespace
if (!new_info->isNamespace)
{
new_info->getVarList();
// goto initial '{'
tok2 = initBaseInfo(new_info, tok);
}
new_info->classStart = tok2;
new_info->classEnd = new_info->classStart->link();
@ -339,10 +346,17 @@ const Token *CheckClass::initBaseInfo(SpaceInfo *info, const Token *tok)
{
// goto initial '{'
const Token *tok2 = tok->tokAt(2);
int level = 0;
while (tok2 && tok2->str() != "{")
{
// skip unsupported templates
if (tok2->str() == "<")
level++;
else if (tok2->str() == ">")
level--;
// check for base classes
if (Token::Match(tok2, ":|,"))
else if (level == 0 && Token::Match(tok2, ":|,"))
{
BaseInfo base;

View File

@ -147,6 +147,8 @@ private:
TEST_CASE(constVirtualFunc);
TEST_CASE(constIfCfg); // ticket #1881 - fp when there are #if
TEST_CASE(constFriend); // ticket #1921 - fp for friend function
TEST_CASE(symboldatabase1);
}
// Check the operator Equal
@ -4196,6 +4198,18 @@ private:
checkConst(code);
ASSERT_EQUALS("", errout.str());
}
void symboldatabase1()
{
checkConst("namespace foo {\n"
" class bar;\n"
"};");
ASSERT_EQUALS("", errout.str());
checkConst("class foo : public bar < int, int> {\n"
"};");
ASSERT_EQUALS("", errout.str());
}
};
REGISTER_TEST(TestClass)