Fixed #4463 (false positive: (style) Variable 'CHDERR_NOT_OPEN' hides enumerator with same name)
This commit is contained in:
parent
47931372ff
commit
c4763b9010
|
@ -7142,7 +7142,7 @@ bool Tokenizer::duplicateDefinition(Token ** tokPtr, const Token * name) const
|
|||
const Token *back = tok;
|
||||
while (back && back->isName())
|
||||
back = back->previous();
|
||||
if (!back || Token::Match(back, "[(,;{}] !!return")) {
|
||||
if (!back || (Token::Match(back, "[(,;{}]") && !Token::Match(back->next(),"return|throw"))) {
|
||||
duplicateEnumError(*tokPtr, name, "Variable");
|
||||
return true;
|
||||
}
|
||||
|
@ -7461,7 +7461,7 @@ void Tokenizer::simplifyEnum()
|
|||
tok3 = tok3->link(); // skip inner scopes
|
||||
else if (tok3->isName() && enumValues.find(tok3->str()) != enumValues.end()) {
|
||||
const Token *prev = tok3->previous();
|
||||
if ((prev->isName() && !Token::Match(prev, "return|case")) ||
|
||||
if ((prev->isName() && !Token::Match(prev, "return|case|throw")) ||
|
||||
prev->str() == "*" ||
|
||||
Token::Match(prev, "& %type% =")) {
|
||||
// variable declaration?
|
||||
|
|
|
@ -361,6 +361,7 @@ private:
|
|||
TEST_CASE(enum35); // ticket #3953 (avoid simplification of type)
|
||||
TEST_CASE(enum36); // ticket #4378
|
||||
TEST_CASE(enum37); // ticket #4280 (shadow variable)
|
||||
TEST_CASE(enum38); // ticket #4463 (when throwing enum id, don't warn about shadow variable)
|
||||
TEST_CASE(enumscope1); // ticket #3949
|
||||
TEST_CASE(duplicateDefinition); // ticket #3565
|
||||
|
||||
|
@ -7362,6 +7363,12 @@ private:
|
|||
ASSERT_EQUALS("void f ( ) { int & a = x ; }", checkSimplifyEnum(code4));
|
||||
}
|
||||
|
||||
void enum38() { // #4463
|
||||
const char code[] = "enum { a,b }; void f() { throw a; }";
|
||||
checkSimplifyEnum(code);
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void enumscope1() { // #3949 - don't simplify enum from one function in another function
|
||||
const char code[] = "void foo() { enum { A = 0, B = 1 }; }\n"
|
||||
"void bar() { int a = A; }";
|
||||
|
|
Loading…
Reference in New Issue