Tokenizer::setVarId: Fixed problem in initializer list when parameter and class member has same name

This commit is contained in:
Daniel Marjamäki 2012-12-23 19:55:09 +01:00
parent fd10110404
commit 56b7670468
2 changed files with 23 additions and 7 deletions

View File

@ -2591,8 +2591,13 @@ static void setVarIdClassDeclaration(Token * const startToken,
++indentlevel;
} else if (tok->str() == "}")
--indentlevel;
else if (tok->isName() && tok->varId() <= scopeStartVarId) {
if (indentlevel > 0 || (initList && indentlevel == 0 && (tok->strAt(-1) == "," || tok->strAt(-1) == ":"))) {
else if (initList && indentlevel == 0 && Token::Match(tok->previous(), "[,:] %var% (")) {
const std::map<std::string, unsigned int>::const_iterator it = variableId.find(tok->str());
if (it != variableId.end()) {
tok->varId(it->second);
}
} else if (tok->isName() && tok->varId() <= scopeStartVarId) {
if (indentlevel > 0) {
if (Token::Match(tok->previous(), "::|."))
continue;
if (tok->next()->str() == "::") {

View File

@ -4043,16 +4043,27 @@ private:
void varid_initList() {
const char code[] = "class A {\n"
" A() : x(0) {}\n"
" int x;\n"
"};";
const char code1[] = "class A {\n"
" A() : x(0) {}\n"
" int x;\n"
"};";
ASSERT_EQUALS("\n\n##file 0\n"
"1: class A {\n"
"2: A ( ) : x@1 ( 0 ) { }\n"
"3: int x@1 ;\n"
"4: } ;\n",
tokenizeDebugListing(code));
tokenizeDebugListing(code1));
const char code2[] = "class A {\n"
" A(int x) : x(x) {}\n"
" int x;\n"
"};";
ASSERT_EQUALS("\n\n##file 0\n"
"1: class A {\n"
"2: A ( int x@1 ) : x@2 ( x@1 ) { }\n"
"3: int x@2 ;\n"
"4: } ;\n",
tokenizeDebugListing(code2));
}
void varid_operator() {