Tokenizer::simplifyEnum: Fixed internalErrors when building with compiled patterns.
This commit is contained in:
parent
fa1fd31667
commit
8b5792a0f8
|
@ -7439,6 +7439,10 @@ void Tokenizer::simplifyEnum()
|
||||||
for (const Token* arg = tok2; arg && arg->str() != "("; arg = arg->previous()) {
|
for (const Token* arg = tok2; arg && arg->str() != "("; arg = arg->previous()) {
|
||||||
if (Token::Match(arg, "%type% [,)]") && enumValues.find(arg->str()) != enumValues.end()) {
|
if (Token::Match(arg, "%type% [,)]") && enumValues.find(arg->str()) != enumValues.end()) {
|
||||||
shadowArg.insert(arg->str());
|
shadowArg.insert(arg->str());
|
||||||
|
if (_settings->isEnabled("style")) {
|
||||||
|
const EnumValue enumValue = enumValues.find(arg->str())->second;
|
||||||
|
duplicateEnumError(arg, enumValue.name, "Function argument");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!shadowArg.empty()) {
|
if (!shadowArg.empty()) {
|
||||||
|
@ -7455,8 +7459,17 @@ void Tokenizer::simplifyEnum()
|
||||||
if (tok3->str() == "{")
|
if (tok3->str() == "{")
|
||||||
tok3 = tok3->link(); // skip inner scopes
|
tok3 = tok3->link(); // skip inner scopes
|
||||||
else if (tok3->isName() && enumValues.find(tok3->str()) != enumValues.end()) {
|
else if (tok3->isName() && enumValues.find(tok3->str()) != enumValues.end()) {
|
||||||
if (Token::Match(tok3->previous(), "*|%type%") || Token::Match(tok3->previous(), "& %type% =")) // variable declaration?
|
const Token *prev = tok3->previous();
|
||||||
|
if ((prev->isName() && !Token::Match(prev, "return|case")) ||
|
||||||
|
prev->str() == "*" ||
|
||||||
|
Token::Match(prev, "& %type% =")) {
|
||||||
|
// variable declaration?
|
||||||
shadowVars.insert(tok3->str());
|
shadowVars.insert(tok3->str());
|
||||||
|
if (_settings->isEnabled("style")) {
|
||||||
|
const EnumValue enumValue = enumValues.find(tok3->str())->second;
|
||||||
|
duplicateEnumError(tok3, enumValue.name, "Variable");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!shadowVars.empty()) {
|
if (!shadowVars.empty()) {
|
||||||
|
|
|
@ -7232,7 +7232,9 @@ private:
|
||||||
" x+=1;\n"
|
" x+=1;\n"
|
||||||
"}\n";
|
"}\n";
|
||||||
checkSimplifyEnum(code);
|
checkSimplifyEnum(code);
|
||||||
ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:1]: (style) Variable 'x' hides enumerator with same name\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:1]: (style) Variable 'x' hides enumerator with same name\n"
|
||||||
|
"[test.cpp:6] -> [test.cpp:1]: (style) Function argument 'x' hides enumerator with same name\n",
|
||||||
|
errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void enum23() { // ticket #2804
|
void enum23() { // ticket #2804
|
||||||
|
|
Loading…
Reference in New Issue