Symbol database: add support for class inline functions with classes
This commit is contained in:
parent
36b03bdd3e
commit
508c171945
|
@ -232,9 +232,11 @@ void CheckClass::addNewFunction(SpaceInfo **info, const Token **tok)
|
|||
SpaceInfo *new_info = new SpaceInfo(this, tok1, *info);
|
||||
|
||||
// skip to start of function
|
||||
while (tok1->str() != "{")
|
||||
while (tok1 && tok1->str() != "{")
|
||||
tok1 = tok1->next();
|
||||
|
||||
if (tok1)
|
||||
{
|
||||
new_info->classStart = tok1;
|
||||
new_info->classEnd = tok1->link();
|
||||
|
||||
|
@ -245,6 +247,7 @@ void CheckClass::addNewFunction(SpaceInfo **info, const Token **tok)
|
|||
|
||||
*tok = tok1;
|
||||
}
|
||||
}
|
||||
|
||||
void CheckClass::addIfFunction(SpaceInfo **info, const Token **tok)
|
||||
{
|
||||
|
@ -459,6 +462,8 @@ void CheckClass::createSymbolDatabase()
|
|||
{
|
||||
// find the function implementation later
|
||||
tok = end->next();
|
||||
|
||||
info->functionList.push_back(function);
|
||||
}
|
||||
|
||||
// inline function
|
||||
|
@ -468,16 +473,14 @@ void CheckClass::createSymbolDatabase()
|
|||
function.hasBody = true;
|
||||
function.arg = function.argDef;
|
||||
|
||||
// skip over function body
|
||||
tok = end->next();
|
||||
while (tok && tok->str() != "{")
|
||||
tok = tok->next();
|
||||
if (!tok)
|
||||
return;
|
||||
tok = tok->link();
|
||||
}
|
||||
|
||||
info->functionList.push_back(function);
|
||||
|
||||
const Token *tok2 = funcStart;
|
||||
|
||||
addNewFunction(&info, &tok2);
|
||||
|
||||
tok = tok2;
|
||||
}
|
||||
}
|
||||
|
||||
// nested class function?
|
||||
|
@ -502,20 +505,8 @@ void CheckClass::createSymbolDatabase()
|
|||
|
||||
// not in SpaceInfo
|
||||
else
|
||||
{
|
||||
// found a "?" skip until the end of statement is found to avoid detecting
|
||||
// false functions..
|
||||
if (tok->str() == "?")
|
||||
{
|
||||
while (tok && !Token::Match(tok, "[;{}]"))
|
||||
tok = tok->next();
|
||||
if (!tok)
|
||||
break;
|
||||
}
|
||||
|
||||
addIfFunction(&info, &tok);
|
||||
}
|
||||
}
|
||||
|
||||
std::list<SpaceInfo *>::iterator it;
|
||||
|
||||
|
@ -1417,7 +1408,14 @@ void CheckClass::privateFunctions()
|
|||
|
||||
std::list<const Token *> FuncList;
|
||||
/** @todo embedded class have access to private functions */
|
||||
if (info->nestedList.empty())
|
||||
int nested = 0;
|
||||
std::list<SpaceInfo *>::const_iterator ni;
|
||||
for (ni = info->nestedList.begin(); ni != info->nestedList.end(); ++ni)
|
||||
{
|
||||
if ((*ni)->type != SpaceInfo::Function)
|
||||
nested++;
|
||||
}
|
||||
if (!nested)
|
||||
{
|
||||
for (func = info->functionList.begin(); func != info->functionList.end(); ++func)
|
||||
{
|
||||
|
|
|
@ -490,6 +490,51 @@ private:
|
|||
"}\n");
|
||||
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
check("class Foo {\n"
|
||||
" void func1()\n"
|
||||
" {\n"
|
||||
" struct Fred\n"
|
||||
" {\n"
|
||||
" int a;\n"
|
||||
" Fred() { a = 0; }\n"
|
||||
" };\n"
|
||||
" }\n"
|
||||
"\n"
|
||||
" void func2()\n"
|
||||
" {\n"
|
||||
" struct Fred\n"
|
||||
" {\n"
|
||||
" int b;\n"
|
||||
" Fred() { b = 0; }\n"
|
||||
" };\n"
|
||||
" }\n"
|
||||
"};\n");
|
||||
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
check("class Foo {\n"
|
||||
" void func1()\n"
|
||||
" {\n"
|
||||
" struct Fred\n"
|
||||
" {\n"
|
||||
" int a;\n"
|
||||
" Fred() { }\n"
|
||||
" };\n"
|
||||
" }\n"
|
||||
"\n"
|
||||
" void func2()\n"
|
||||
" {\n"
|
||||
" struct Fred\n"
|
||||
" {\n"
|
||||
" int b;\n"
|
||||
" Fred() { }\n"
|
||||
" };\n"
|
||||
" }\n"
|
||||
"};\n");
|
||||
|
||||
ASSERT_EQUALS("[test.cpp:7]: (warning) Member variable not initialized in the constructor 'Fred::a'\n"
|
||||
"[test.cpp:16]: (warning) Member variable not initialized in the constructor 'Fred::b'\n", errout.str());
|
||||
}
|
||||
|
||||
void initvar_chained_assign()
|
||||
|
|
Loading…
Reference in New Issue