Tokenizer::setVarId: Fixed problem in initializer list when parameter and class member has same name
This commit is contained in:
parent
fd10110404
commit
56b7670468
|
@ -2591,8 +2591,13 @@ static void setVarIdClassDeclaration(Token * const startToken,
|
||||||
++indentlevel;
|
++indentlevel;
|
||||||
} else if (tok->str() == "}")
|
} else if (tok->str() == "}")
|
||||||
--indentlevel;
|
--indentlevel;
|
||||||
else if (tok->isName() && tok->varId() <= scopeStartVarId) {
|
else if (initList && indentlevel == 0 && Token::Match(tok->previous(), "[,:] %var% (")) {
|
||||||
if (indentlevel > 0 || (initList && indentlevel == 0 && (tok->strAt(-1) == "," || tok->strAt(-1) == ":"))) {
|
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(), "::|."))
|
if (Token::Match(tok->previous(), "::|."))
|
||||||
continue;
|
continue;
|
||||||
if (tok->next()->str() == "::") {
|
if (tok->next()->str() == "::") {
|
||||||
|
|
|
@ -4043,16 +4043,27 @@ private:
|
||||||
|
|
||||||
|
|
||||||
void varid_initList() {
|
void varid_initList() {
|
||||||
const char code[] = "class A {\n"
|
const char code1[] = "class A {\n"
|
||||||
" A() : x(0) {}\n"
|
" A() : x(0) {}\n"
|
||||||
" int x;\n"
|
" int x;\n"
|
||||||
"};";
|
"};";
|
||||||
ASSERT_EQUALS("\n\n##file 0\n"
|
ASSERT_EQUALS("\n\n##file 0\n"
|
||||||
"1: class A {\n"
|
"1: class A {\n"
|
||||||
"2: A ( ) : x@1 ( 0 ) { }\n"
|
"2: A ( ) : x@1 ( 0 ) { }\n"
|
||||||
"3: int x@1 ;\n"
|
"3: int x@1 ;\n"
|
||||||
"4: } ;\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() {
|
void varid_operator() {
|
||||||
|
|
Loading…
Reference in New Issue