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;
|
||||
} 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() == "::") {
|
||||
|
|
|
@ -4043,7 +4043,7 @@ private:
|
|||
|
||||
|
||||
void varid_initList() {
|
||||
const char code[] = "class A {\n"
|
||||
const char code1[] = "class A {\n"
|
||||
" A() : x(0) {}\n"
|
||||
" int x;\n"
|
||||
"};";
|
||||
|
@ -4052,7 +4052,18 @@ private:
|
|||
"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() {
|
||||
|
|
Loading…
Reference in New Issue