Fixed #2252 (segmentation fault with enable=all)

This commit is contained in:
Robert Reif 2010-11-30 19:40:32 +01:00 committed by Daniel Marjamäki
parent 0081800a20
commit f90236a183
2 changed files with 100 additions and 1 deletions

View File

@ -912,12 +912,24 @@ void SymbolDatabase::SpaceInfo::getVarList()
vartok = tok->tokAt(3);
tok = vartok->next();
}
else if (Token::Match(tok, ":: %type% :: %type% %var% ;"))
{
isClass = true;
vartok = tok->tokAt(4);
tok = vartok->next();
}
else if (Token::Match(tok, "%type% :: %type% :: %type% %var% ;"))
{
isClass = true;
vartok = tok->tokAt(5);
tok = vartok->next();
}
else if (Token::Match(tok, ":: %type% :: %type% :: %type% %var% ;"))
{
isClass = true;
vartok = tok->tokAt(6);
tok = vartok->next();
}
// Structure?
else if (Token::Match(tok, "struct|union %type% %var% ;"))
@ -976,8 +988,11 @@ void SymbolDatabase::SpaceInfo::getVarList()
}
// Container..
else if (Token::Match(tok, "%type% :: %type% :: %type% <") ||
else if (Token::Match(tok, ":: %type% :: %type% :: %type% <") ||
Token::Match(tok, "%type% :: %type% :: %type% <") ||
Token::Match(tok, ":: %type% :: %type% <") ||
Token::Match(tok, "%type% :: %type% <") ||
Token::Match(tok, ":: %type% <") ||
Token::Match(tok, "%type% <"))
{
// got an unhandled template?
@ -1015,6 +1030,12 @@ void SymbolDatabase::SpaceInfo::getVarList()
vartok = tok->next();
tok = vartok->next();
}
else if (tok && (Token::Match(tok, "> :: %type% %var% ;") || Token::Match(tok, ">> :: %type% %var% ;")))
{
isClass = true;
vartok = tok->tokAt(3);
tok = vartok->next();
}
else if (tok && (Token::Match(tok, "> * %var% ;") || Token::Match(tok, ">> * %var% ;")))
{
vartok = tok->tokAt(2);

View File

@ -152,6 +152,7 @@ private:
TEST_CASE(const38); // ticket #2135
TEST_CASE(const39);
TEST_CASE(const40); // ticket #2228
TEST_CASE(const41); // ticket #2255
TEST_CASE(constoperator1); // operator< can often be const
TEST_CASE(constoperator2); // operator<<
TEST_CASE(constoperator3);
@ -4434,6 +4435,83 @@ private:
ASSERT_EQUALS("", errout.str());
}
void const41() // ticket #2255
{
checkConst("class Fred\n"
"{\n"
" ::std::string m_name;\n"
"public:\n"
" void SetName(const ::std::string & name)\n"
" {\n"
" m_name = name;\n"
" }\n"
"};\n");
ASSERT_EQUALS("", errout.str());
checkConst("class SharedPtrHolder\n"
"{\n"
" ::std::tr1::shared_ptr<int> pNum;\n"
" public :\n"
" void SetNum(const ::std::tr1::shared_ptr<int> & apNum)\n"
" {\n"
" pNum = apNum;\n"
" }\n"
"};\n");
ASSERT_EQUALS("", errout.str());
checkConst("class SharedPtrHolder2\n"
"{\n"
" public:\n"
" typedef ::std::tr1::shared_ptr<int> IntSharedPtr;\n"
" private:\n"
" IntSharedPtr pNum;\n"
" public :\n"
" void SetNum(const IntSharedPtr & apNum)\n"
" {\n"
" pNum = apNum;\n"
" }\n"
"};\n");
ASSERT_EQUALS("", errout.str());
checkConst("struct IntPtrTypes\n"
"{\n"
" typedef ::std::tr1::shared_ptr<int> Shared;\n"
"};\n"
"class SharedPtrHolder3\n"
"{\n"
" private:\n"
" IntPtrTypes::Shared pNum;\n"
" public :\n"
" void SetNum(const IntPtrTypes::Shared & apNum)\n"
" {\n"
" pNum = apNum;\n"
" }\n"
"};\n");
ASSERT_EQUALS("", errout.str());
checkConst("template <typename T>\n"
"struct PtrTypes\n"
"{\n"
" typedef ::std::tr1::shared_ptr<T> Shared;\n"
"};\n"
"class SharedPtrHolder4\n"
"{\n"
" private:\n"
" PtrTypes<int>::Shared pNum;\n"
" public :\n"
" void SetNum(const PtrTypes<int>::Shared & apNum)\n"
" {\n"
" pNum = apNum;\n"
" }\n"
"};\n");
ASSERT_EQUALS("", errout.str());
}
// increment/decrement => not const
void constincdec()
{