Fixed #9879 (Tokenizer: Better handling of operator() '(*this)(...)')
This commit is contained in:
parent
638088dc04
commit
cfd41fea83
|
@ -11222,6 +11222,13 @@ void Tokenizer::simplifyOverloadedOperators()
|
|||
if (!tok->isName())
|
||||
continue;
|
||||
|
||||
if (Token::simpleMatch(tok, "this ) (") && Token::simpleMatch(tok->tokAt(-2), "( *")) {
|
||||
tok = tok->next();
|
||||
tok->insertToken("operator()");
|
||||
tok->insertToken(".");
|
||||
continue;
|
||||
}
|
||||
|
||||
// Get classes that have operator() member
|
||||
if (Token::Match(tok, "class|struct %name% [:{]")) {
|
||||
int indent = 0;
|
||||
|
@ -11237,6 +11244,7 @@ void Tokenizer::simplifyOverloadedOperators()
|
|||
tok2 = tok2->link();
|
||||
} else if (indent == 1 && Token::simpleMatch(tok2, "operator() (") && isFunctionHead(tok2->next(), ";{")) {
|
||||
classNames.insert(tok->strAt(1));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -417,6 +417,7 @@ private:
|
|||
TEST_CASE(simplifyOperatorName27);
|
||||
|
||||
TEST_CASE(simplifyOverloadedOperators1);
|
||||
TEST_CASE(simplifyOverloadedOperators2); // (*this)(123)
|
||||
|
||||
TEST_CASE(simplifyNullArray);
|
||||
|
||||
|
@ -6652,6 +6653,18 @@ private:
|
|||
tokenizeAndStringify(code));
|
||||
}
|
||||
|
||||
void simplifyOverloadedOperators2() { // #9879 - (*this)(123);
|
||||
const char code[] = "struct S {\n"
|
||||
" void operator()(int);\n"
|
||||
" void foo() { (*this)(123); }\n"
|
||||
"};\n";
|
||||
ASSERT_EQUALS("struct S {\n"
|
||||
"void operator() ( int ) ;\n"
|
||||
"void foo ( ) { ( * this ) . operator() ( 123 ) ; }\n"
|
||||
"} ;",
|
||||
tokenizeAndStringify(code));
|
||||
}
|
||||
|
||||
void simplifyNullArray() {
|
||||
ASSERT_EQUALS("* ( foo . bar [ 5 ] ) = x ;", tokenizeAndStringify("0[foo.bar[5]] = x;"));
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue