Fixed setVarId() for destructors
This commit is contained in:
parent
6ee4cf80dc
commit
e990cfb76b
|
@ -2885,11 +2885,14 @@ void Tokenizer::setVarId()
|
||||||
std::list<Token *> allMemberVars;
|
std::list<Token *> allMemberVars;
|
||||||
if (!isC()) {
|
if (!isC()) {
|
||||||
for (Token *tok2 = list.front(); tok2; tok2 = tok2->next()) {
|
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();
|
const Token* tok3 = tok2->next();
|
||||||
do {
|
do {
|
||||||
tok3 = tok3->tokAt(2);
|
tok3 = tok3->next();
|
||||||
} while (Token::Match(tok3, ":: %name%"));
|
if (tok3->str() == "~")
|
||||||
|
tok3 = tok3->next();
|
||||||
|
tok3 = tok3->next();
|
||||||
|
} while (Token::Match(tok3, ":: ~| %name%"));
|
||||||
if (!tok3)
|
if (!tok3)
|
||||||
syntaxError(tok2);
|
syntaxError(tok2);
|
||||||
const std::string& str3 = tok3->str();
|
const std::string& str3 = tok3->str();
|
||||||
|
@ -2961,14 +2964,18 @@ void Tokenizer::setVarId()
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// Set variable ids in member functions for this class..
|
// 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) {
|
for (std::list<Token *>::iterator func = allMemberFunctions.begin(); func != allMemberFunctions.end(); ++func) {
|
||||||
Token *tok2 = *func;
|
Token *tok2 = *func;
|
||||||
|
|
||||||
// Found a class function..
|
// Found a class function..
|
||||||
if (Token::Match(tok2, funcpattern.c_str())) {
|
if (Token::Match(tok2, funcpattern.c_str())) {
|
||||||
// Goto the end parentheses..
|
// 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)
|
if (!tok2)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
|
@ -119,6 +119,7 @@ private:
|
||||||
TEST_CASE(varid_in_class16);
|
TEST_CASE(varid_in_class16);
|
||||||
TEST_CASE(varid_in_class17); // #6056 - no varid for member functions
|
TEST_CASE(varid_in_class17); // #6056 - no varid for member functions
|
||||||
TEST_CASE(varid_in_class18); // #7127
|
TEST_CASE(varid_in_class18); // #7127
|
||||||
|
TEST_CASE(varid_in_class19);
|
||||||
TEST_CASE(varid_initList);
|
TEST_CASE(varid_initList);
|
||||||
TEST_CASE(varid_initListWithBaseTemplate);
|
TEST_CASE(varid_initListWithBaseTemplate);
|
||||||
TEST_CASE(varid_operator);
|
TEST_CASE(varid_operator);
|
||||||
|
@ -1765,6 +1766,24 @@ private:
|
||||||
"10: { }\n", tokenize(code, false, "test.cpp"));
|
"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() {
|
void varid_initList() {
|
||||||
const char code1[] = "class A {\n"
|
const char code1[] = "class A {\n"
|
||||||
" A() : x(0) {}\n"
|
" A() : x(0) {}\n"
|
||||||
|
|
Loading…
Reference in New Issue