Symbol database: Fixed bug. Ticket: #2149

This commit is contained in:
Robert Reif 2010-11-04 06:58:37 +01:00 committed by Daniel Marjamäki
parent cf0403434d
commit 003f99da82
3 changed files with 32 additions and 41 deletions

View File

@ -111,7 +111,7 @@ void CheckClass::addFunction(SpaceInfo **info, const Token **tok)
unsigned int path_length = 0;
// back up to head of path
while (tok1->previous()->str() == "::")
while (tok1->previous() && tok1->previous()->str() == "::")
{
path = tok1->str() + " :: " + path;
tok1 = tok1->tokAt(-2);
@ -227,6 +227,28 @@ void CheckClass::addNewFunction(SpaceInfo **info, const Token **tok)
*tok = tok1;
}
void CheckClass::addIfFunction(SpaceInfo **info, const Token **tok)
{
const Token *funcStart = 0;
const Token *argStart = 0;
// function?
if (isFunction(*tok, &funcStart, &argStart))
{
// 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);
}
}
}
void CheckClass::createSymbolDatabase()
{
// Multiple calls => bail out
@ -441,50 +463,12 @@ void CheckClass::createSymbolDatabase()
}
}
else if (info->type == SpaceInfo::Namespace)
{
const Token *funcStart = 0;
const Token *argStart = 0;
// function?
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);
}
}
}
addIfFunction(&info, &tok);
}
// not in SpaceInfo
else
{
const Token *funcStart = 0;
const Token *argStart = 0;
// function?
if (isFunction(tok, &funcStart, &argStart))
{
// 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);
}
}
}
addIfFunction(&info, &tok);
}
std::list<SpaceInfo *>::iterator it;

View File

@ -318,6 +318,8 @@ private:
void addFunction(SpaceInfo **info, const Token **tok);
void addNewFunction(SpaceInfo **info, const Token **tok);
void addIfFunction(SpaceInfo **info, const Token **tok);
/** @brief Information about all namespaces/classes/structrues */
std::list<SpaceInfo *> spaceInfoList;

View File

@ -4767,6 +4767,11 @@ private:
" static void function_declaration_after(void) __attribute__((__used__));\n"
"}\n");
ASSERT_EQUALS("", errout.str());
checkConst("testing::testing()\n"
"{\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}
};