Fixed handling of this-> and (*this). in setVarId()
This commit is contained in:
parent
db342ea910
commit
49a9b011eb
|
@ -2606,7 +2606,7 @@ void Tokenizer::setVarIdClassDeclaration(Token * const startToken,
|
|||
}
|
||||
} else if (tok->isName() && tok->varId() <= scopeStartVarId) {
|
||||
if (indentlevel > 0) {
|
||||
if (Token::Match(tok->previous(), "::|."))
|
||||
if (Token::Match(tok->previous(), "::|.") && tok->strAt(-2) != "this" && !Token::Match(tok->tokAt(-5), "( * this ) ."))
|
||||
continue;
|
||||
if (tok->next()->str() == "::") {
|
||||
if (tok->str() == className)
|
||||
|
@ -2644,7 +2644,7 @@ static void setVarIdClassFunction(const std::string &classname,
|
|||
continue;
|
||||
if (Token::Match(tok2->tokAt(-4), "%name% :: %name% ::")) // Currently unsupported
|
||||
continue;
|
||||
if (Token::Match(tok2->tokAt(-2), "!!this ."))
|
||||
if (Token::Match(tok2->tokAt(-2), "!!this .") && !Token::Match(tok2->tokAt(-5), "( * this ) ."))
|
||||
continue;
|
||||
|
||||
const std::map<std::string,unsigned int>::const_iterator it = varlist.find(tok2->str());
|
||||
|
|
|
@ -1646,15 +1646,39 @@ private:
|
|||
}
|
||||
|
||||
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", tokenize(code, false, "test.cpp"));
|
||||
{
|
||||
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", tokenize(code, false, "test.cpp"));
|
||||
}
|
||||
{
|
||||
const char code[] = "class Fred {\n"
|
||||
" void foo(int x) { this->x = x; }\n"
|
||||
" int x;\n"
|
||||
"};\n";
|
||||
ASSERT_EQUALS("\n\n##file 0\n"
|
||||
"1: class Fred {\n"
|
||||
"2: void foo ( int x@1 ) { this . x@2 = x@1 ; }\n"
|
||||
"3: int x@2 ;\n"
|
||||
"4: } ;\n", tokenize(code, false, "test.cpp"));
|
||||
}
|
||||
{
|
||||
const char code[] = "class Fred {\n"
|
||||
" void foo(int x) { (*this).x = x; }\n"
|
||||
" int x;\n"
|
||||
"};\n";
|
||||
ASSERT_EQUALS("\n\n##file 0\n"
|
||||
"1: class Fred {\n"
|
||||
"2: void foo ( int x@1 ) { ( * this ) . x@2 = x@1 ; }\n"
|
||||
"3: int x@2 ;\n"
|
||||
"4: } ;\n", tokenize(code, false, "test.cpp"));
|
||||
}
|
||||
}
|
||||
|
||||
void varid_in_class17() { // #6056 - Set no varid for member functions
|
||||
|
|
Loading…
Reference in New Issue