Tokenizer::setVarId: Fixed problem with initializer lists (#4436)
This commit is contained in:
parent
a43ae677d7
commit
bf9b900c30
|
@ -2818,7 +2818,7 @@ void Tokenizer::setVarId()
|
||||||
std::map<std::string, unsigned int> varlist;
|
std::map<std::string, unsigned int> varlist;
|
||||||
const Token* tokStart = Token::findsimplematch(tok, "{");
|
const Token* tokStart = Token::findsimplematch(tok, "{");
|
||||||
if (tokStart) {
|
if (tokStart) {
|
||||||
for (const Token *tok2 = tokStart->next(); tok2 != tok->link(); tok2 = tok2->next()) {
|
for (const Token *tok2 = tokStart->next(); tok2 != tokStart->link(); tok2 = tok2->next()) {
|
||||||
// skip parentheses..
|
// skip parentheses..
|
||||||
if (tok2->str() == "{")
|
if (tok2->str() == "{")
|
||||||
tok2 = tok2->link();
|
tok2 = tok2->link();
|
||||||
|
@ -2866,8 +2866,11 @@ void Tokenizer::setVarId()
|
||||||
|
|
||||||
// constructor with initializer list
|
// constructor with initializer list
|
||||||
if (Token::Match(tok2, ") : %var% (")) {
|
if (Token::Match(tok2, ") : %var% (")) {
|
||||||
const Token *tok3 = tok2;
|
Token *tok3 = tok2;
|
||||||
while (Token::Match(tok3, ") [:,] %var% (")) {
|
while (Token::Match(tok3, ") [:,] %var% (")) {
|
||||||
|
Token *vartok = tok3->tokAt(2);
|
||||||
|
if (varlist.find(vartok->str()) != varlist.end())
|
||||||
|
vartok->varId(varlist[vartok->str()]);
|
||||||
tok3 = tok3->linkAt(3);
|
tok3 = tok3->linkAt(3);
|
||||||
}
|
}
|
||||||
if (Token::simpleMatch(tok3, ") {")) {
|
if (Token::simpleMatch(tok3, ") {")) {
|
||||||
|
|
|
@ -4067,6 +4067,19 @@ private:
|
||||||
"3: int x@2 ;\n"
|
"3: int x@2 ;\n"
|
||||||
"4: } ;\n",
|
"4: } ;\n",
|
||||||
tokenizeDebugListing(code2));
|
tokenizeDebugListing(code2));
|
||||||
|
|
||||||
|
const char code3[] = "class A {\n"
|
||||||
|
" A(int x);\n"
|
||||||
|
" int x;\n"
|
||||||
|
"};\n"
|
||||||
|
"A::A(int x) : x(x) {}";
|
||||||
|
ASSERT_EQUALS("\n\n##file 0\n"
|
||||||
|
"1: class A {\n"
|
||||||
|
"2: A ( int x@1 ) ;\n"
|
||||||
|
"3: int x@2 ;\n"
|
||||||
|
"4: } ;\n"
|
||||||
|
"5: A :: A ( int x@3 ) : x@2 ( x@3 ) { }\n",
|
||||||
|
tokenizeDebugListing(code3));
|
||||||
}
|
}
|
||||||
|
|
||||||
void varid_operator() {
|
void varid_operator() {
|
||||||
|
|
Loading…
Reference in New Issue