Fixed #7444 (Tokenizer::varId: Wrong varid when there is anonumous union in class)
This commit is contained in:
parent
bf8471e109
commit
b965cf5491
|
@ -2640,9 +2640,14 @@ void Tokenizer::setVarId()
|
||||||
functionDeclEndStack.push(newFunctionDeclEnd);
|
functionDeclEndStack.push(newFunctionDeclEnd);
|
||||||
scopeInfo.push(variableId);
|
scopeInfo.push(variableId);
|
||||||
}
|
}
|
||||||
} else if (tok->str() == "{") {
|
} else if (Token::Match(tok, "{|}")) {
|
||||||
|
const Token * const startToken = (tok->str() == "{") ? tok : tok->link();
|
||||||
|
|
||||||
// parse anonymous unions as part of the current scope
|
// parse anonymous unions as part of the current scope
|
||||||
if (!(initlist && Token::Match(tok->previous(), "%name%|>|>>") && Token::Match(tok->link(), "} ,|{"))) {
|
if (!Token::Match(startToken->previous(), "union|struct|enum {") &&
|
||||||
|
!(initlist && Token::Match(startToken->previous(), "%name%|>|>>") && Token::Match(startToken->link(), "} ,|{"))) {
|
||||||
|
|
||||||
|
if (tok->str() == "{") {
|
||||||
bool isExecutable;
|
bool isExecutable;
|
||||||
if (tok->strAt(-1) == ")" || Token::Match(tok->tokAt(-2), ") %type%") ||
|
if (tok->strAt(-1) == ")" || Token::Match(tok->tokAt(-2), ") %type%") ||
|
||||||
(initlist && tok->strAt(-1) == "}")) {
|
(initlist && tok->strAt(-1) == "}")) {
|
||||||
|
@ -2654,11 +2659,7 @@ void Tokenizer::setVarId()
|
||||||
}
|
}
|
||||||
initlist = false;
|
initlist = false;
|
||||||
scopeStack.push(scopeStackEntryType(isExecutable, _varId));
|
scopeStack.push(scopeStackEntryType(isExecutable, _varId));
|
||||||
}
|
} else { /* if (tok->str() == "}") */
|
||||||
} else if (tok->str() == "}") {
|
|
||||||
// parse anonymous unions/structs as part of the current scope
|
|
||||||
if (!(Token::simpleMatch(tok, "} ;") && tok->link() && Token::Match(tok->link()->previous(), "union|struct|enum {")) &&
|
|
||||||
!(initlist && Token::Match(tok, "} ,|{") && Token::Match(tok->link()->previous(), "%name%|>|>> {"))) {
|
|
||||||
bool isNamespace = false;
|
bool isNamespace = false;
|
||||||
for (const Token *tok1 = tok->link()->previous(); tok1 && tok1->isName(); tok1 = tok1->previous())
|
for (const Token *tok1 = tok->link()->previous(); tok1 && tok1->isName(); tok1 = tok1->previous())
|
||||||
isNamespace |= (tok1->str() == "namespace");
|
isNamespace |= (tok1->str() == "namespace");
|
||||||
|
@ -2683,6 +2684,7 @@ void Tokenizer::setVarId()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (tok == list.front() || Token::Match(tok, "[;{}]") ||
|
if (tok == list.front() || Token::Match(tok, "[;{}]") ||
|
||||||
(tok->str() == "(" && isFunctionHead(tok,"{")) ||
|
(tok->str() == "(" && isFunctionHead(tok,"{")) ||
|
||||||
|
|
|
@ -1628,6 +1628,18 @@ private:
|
||||||
"9: h ( a@1 , b@2 , c@3 , d@4 ) ;\n"
|
"9: h ( a@1 , b@2 , c@3 , d@4 ) ;\n"
|
||||||
"10: }\n",
|
"10: }\n",
|
||||||
tokenize(code3));
|
tokenize(code3));
|
||||||
|
|
||||||
|
// #7444
|
||||||
|
const char code4[] = "class Foo {\n"
|
||||||
|
" void f(float a) { this->a = a; }\n"
|
||||||
|
" union { float a; int b; };\n"
|
||||||
|
"};";
|
||||||
|
ASSERT_EQUALS("\n\n##file 0\n"
|
||||||
|
"1: class Foo {\n"
|
||||||
|
"2: void f ( float a@1 ) { this . a@2 = a@1 ; }\n"
|
||||||
|
"3: union { float a@2 ; int b@3 ; } ;\n"
|
||||||
|
"4: } ;\n",
|
||||||
|
tokenize(code4));
|
||||||
}
|
}
|
||||||
|
|
||||||
void varid_in_class12() { // #4637 - method
|
void varid_in_class12() { // #4637 - method
|
||||||
|
|
Loading…
Reference in New Issue