Fixed #4857 (False Positive: function argument hides enumerator of same type)
This commit is contained in:
parent
b31c218773
commit
a9bd6cf3df
|
@ -7448,10 +7448,31 @@ void Tokenizer::simplifyEnum()
|
||||||
|
|
||||||
// are there shadow arguments?
|
// are there shadow arguments?
|
||||||
if (Token::simpleMatch(tok2->previous(), ") {") || Token::simpleMatch(tok2->tokAt(-2), ") const {")) {
|
if (Token::simpleMatch(tok2->previous(), ") {") || Token::simpleMatch(tok2->tokAt(-2), ") const {")) {
|
||||||
|
// Determine if this is a executable scope..
|
||||||
|
bool executableScope = false;
|
||||||
|
{
|
||||||
|
const Token *prev = tok2->previous()->link();
|
||||||
|
while (prev) {
|
||||||
|
if (prev->str() == "}")
|
||||||
|
prev = prev->link();
|
||||||
|
else if (prev->str() == "{") {
|
||||||
|
while ((prev = prev->previous()) && (prev->isName()));
|
||||||
|
if (!prev || prev->str() == ")")
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
prev = prev->previous();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (prev)
|
||||||
|
executableScope = true;
|
||||||
|
}
|
||||||
|
|
||||||
std::set<std::string> shadowArg;
|
std::set<std::string> shadowArg;
|
||||||
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->previous(), "%type%|*|& %type% [,)]") &&
|
if (Token::Match(arg->previous(), "%type%|*|& %type% [,)]") &&
|
||||||
enumValues.find(arg->str()) != enumValues.end()) {
|
enumValues.find(arg->str()) != enumValues.end()) {
|
||||||
|
if (executableScope && Token::Match(arg->previous(), "[*&]"))
|
||||||
|
continue;
|
||||||
shadowArg.insert(arg->str());
|
shadowArg.insert(arg->str());
|
||||||
if (inScope && _settings->isEnabled("style")) {
|
if (inScope && _settings->isEnabled("style")) {
|
||||||
const EnumValue enumValue = enumValues.find(arg->str())->second;
|
const EnumValue enumValue = enumValues.find(arg->str())->second;
|
||||||
|
|
|
@ -7383,6 +7383,10 @@ private:
|
||||||
|
|
||||||
const char code4[] = "enum { a, b }; void f() { int &a=x; }";
|
const char code4[] = "enum { a, b }; void f() { int &a=x; }";
|
||||||
ASSERT_EQUALS("void f ( ) { int & a = x ; }", checkSimplifyEnum(code4));
|
ASSERT_EQUALS("void f ( ) { int & a = x ; }", checkSimplifyEnum(code4));
|
||||||
|
|
||||||
|
// #4857 - not shadow variable
|
||||||
|
checkSimplifyEnum("enum { a,b }; void f() { if (x) { } else if ( x & a ) {} }");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void enum38() { // #4463
|
void enum38() { // #4463
|
||||||
|
|
Loading…
Reference in New Issue