Fixed setVarId() for destructors

This commit is contained in:
PKEuS 2015-11-18 21:13:58 +01:00
parent 6ee4cf80dc
commit e990cfb76b
2 changed files with 31 additions and 5 deletions

View File

@ -2885,11 +2885,14 @@ void Tokenizer::setVarId()
std::list<Token *> allMemberVars;
if (!isC()) {
for (Token *tok2 = list.front(); tok2; tok2 = tok2->next()) {
if (Token::Match(tok2, "%name% :: %name%")) {
if (Token::Match(tok2, "%name% :: ~| %name%")) {
const Token* tok3 = tok2->next();
do {
tok3 = tok3->tokAt(2);
} while (Token::Match(tok3, ":: %name%"));
tok3 = tok3->next();
if (tok3->str() == "~")
tok3 = tok3->next();
tok3 = tok3->next();
} while (Token::Match(tok3, ":: ~| %name%"));
if (!tok3)
syntaxError(tok2);
const std::string& str3 = tok3->str();
@ -2961,14 +2964,18 @@ void Tokenizer::setVarId()
continue;
// Set variable ids in member functions for this class..
const std::string funcpattern(classname + " :: %name% (");
const std::string funcpattern(classname + " :: ~| %name% (");
for (std::list<Token *>::iterator func = allMemberFunctions.begin(); func != allMemberFunctions.end(); ++func) {
Token *tok2 = *func;
// Found a class function..
if (Token::Match(tok2, funcpattern.c_str())) {
// Goto the end parentheses..
tok2 = tok2->linkAt(nestedCount*2+1);
tok2 = tok2->tokAt(nestedCount*2);
if (tok2 && tok2->str() == "~")
tok2 = tok2->linkAt(2);
else
tok2 = tok2->linkAt(1);
if (!tok2)
break;

View File

@ -119,6 +119,7 @@ private:
TEST_CASE(varid_in_class16);
TEST_CASE(varid_in_class17); // #6056 - no varid for member functions
TEST_CASE(varid_in_class18); // #7127
TEST_CASE(varid_in_class19);
TEST_CASE(varid_initList);
TEST_CASE(varid_initListWithBaseTemplate);
TEST_CASE(varid_operator);
@ -1765,6 +1766,24 @@ private:
"10: { }\n", tokenize(code, false, "test.cpp"));
}
void varid_in_class19() {
const char code[] = "class Fred {\n"
" char *str1;\n"
" ~Fred();\n"
"};\n"
"Fred::~Fred() {\n"
" free(str1);\n"
"}";
ASSERT_EQUALS("\n\n##file 0\n"
"1: class Fred {\n"
"2: char * str1@1 ;\n"
"3: ~ Fred ( ) ;\n"
"4: } ;\n"
"5: Fred :: ~ Fred ( ) {\n"
"6: free ( str1@1 ) ;\n"
"7: }\n", tokenize(code, false, "test.cpp"));
}
void varid_initList() {
const char code1[] = "class A {\n"
" A() : x(0) {}\n"