Fixed bug in setVarId: VarIds for member functions defined inline in class were not properly set
This commit is contained in:
parent
d500f50670
commit
7b1eca700b
|
@ -2426,7 +2426,9 @@ static void setVarIdClassFunction(const std::string &classname,
|
|||
for (Token *tok2 = startToken; tok2 && tok2 != endToken; tok2 = tok2->next()) {
|
||||
if (tok2->varId() != 0 || !tok2->isName())
|
||||
continue;
|
||||
if (Token::Match(tok2->tokAt(-2), ("!!"+classname+" ::").c_str()))
|
||||
if (Token::Match(tok2->tokAt(-2), ("!!" + classname + " ::").c_str()))
|
||||
continue;
|
||||
if (Token::Match(tok2->tokAt(-4), "%var% :: %var% ::")) // Currently unsupported
|
||||
continue;
|
||||
if (Token::Match(tok2->tokAt(-2), "!!this . "))
|
||||
continue;
|
||||
|
@ -2643,12 +2645,14 @@ void Tokenizer::setVarId()
|
|||
std::map<std::string, unsigned int> varlist;
|
||||
const Token* tokStart = Token::findsimplematch(tok, "{");
|
||||
if (tokStart) {
|
||||
for (const Token *tok2 = tokStart->next(); tok2 && tok2 != tokStart->link(); tok2 = tok2->next()) {
|
||||
for (Token *tok2 = tokStart->next(); tok2 && tok2 != tokStart->link(); tok2 = tok2->next()) {
|
||||
// skip parentheses..
|
||||
if (tok2->link()) {
|
||||
if (tok2->str() == "{")
|
||||
if (tok2->str() == "{") {
|
||||
if (tok2->strAt(-1) == ")" || tok2->strAt(-2) == ")")
|
||||
setVarIdClassFunction(classname, tok2, tok2->link(), varlist, &structMembers, &_varId);
|
||||
tok2 = tok2->link();
|
||||
else if (tok2->str() == "(" && tok2->link()->strAt(1) != "(")
|
||||
} else if (tok2->str() == "(" && tok2->link()->strAt(1) != "(")
|
||||
tok2 = tok2->link();
|
||||
}
|
||||
|
||||
|
|
|
@ -295,6 +295,7 @@ private:
|
|||
TEST_CASE(varid_in_class13); // #4637 - method
|
||||
TEST_CASE(varid_in_class14);
|
||||
TEST_CASE(varid_in_class15); // #5533 - functions
|
||||
TEST_CASE(varid_in_class16);
|
||||
TEST_CASE(varid_initList);
|
||||
TEST_CASE(varid_operator);
|
||||
TEST_CASE(varid_throw);
|
||||
|
@ -4586,6 +4587,18 @@ private:
|
|||
"4: }\n", tokenizeDebugListing(code, false, "test.cpp"));
|
||||
}
|
||||
|
||||
void varid_in_class16() { // Set varId for inline member functions
|
||||
const char code[] = "class Fred {\n"
|
||||
" int x;\n"
|
||||
" void foo(int x) { this->x = x; }\n"
|
||||
"}\n";
|
||||
ASSERT_EQUALS("\n\n##file 0\n"
|
||||
"1: class Fred {\n"
|
||||
"2: int x@1 ;\n"
|
||||
"3: void foo ( int x@2 ) { this . x@1 = x@2 ; }\n"
|
||||
"4: }\n", tokenizeDebugListing(code, false, "test.cpp"));
|
||||
}
|
||||
|
||||
void varid_initList() {
|
||||
const char code1[] = "class A {\n"
|
||||
" A() : x(0) {}\n"
|
||||
|
|
Loading…
Reference in New Issue