Fixed #3565 (Variable hides enumerator (attached code example))
This commit is contained in:
parent
c3cb6202ed
commit
aa3cdc6b6f
|
@ -7018,12 +7018,18 @@ bool Tokenizer::duplicateDefinition(Token ** tokPtr, const Token * name) const
|
|||
}
|
||||
}
|
||||
} else {
|
||||
// look backwards
|
||||
if (Token::Match(tok->previous(), "enum|,") ||
|
||||
(Token::Match(tok->previous(), "%type%") &&
|
||||
tok->previous()->str() != "return")) {
|
||||
if (Token::Match(tok->previous(), "enum|,")) {
|
||||
duplicateEnumError(*tokPtr, name, "Variable");
|
||||
return true;
|
||||
} else if (Token::Match(tok->previous(), "%type%")) {
|
||||
// look backwards
|
||||
const Token *back = tok;
|
||||
while (back && back->isName())
|
||||
back = back->previous();
|
||||
if (!back || Token::Match(back, "[(,;{}] !!return")) {
|
||||
duplicateEnumError(*tokPtr, name, "Variable");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -354,6 +354,7 @@ private:
|
|||
TEST_CASE(enum33); // ticket #4015 (segmentation fault)
|
||||
TEST_CASE(enum34); // ticket #4141 (division by zero)
|
||||
TEST_CASE(enumscope1); // ticket #3949
|
||||
TEST_CASE(duplicateDefinition); // ticket #3565
|
||||
|
||||
// remove "std::" on some standard functions
|
||||
TEST_CASE(removestd);
|
||||
|
@ -7176,6 +7177,15 @@ private:
|
|||
ASSERT_EQUALS("void foo ( ) { } void bar ( ) { int a ; a = A ; }", checkSimplifyEnum(code));
|
||||
}
|
||||
|
||||
void duplicateDefinition() { // #3565 - wrongly detects duplicate definition
|
||||
const Settings settings;
|
||||
Tokenizer tokenizer(&settings, NULL);
|
||||
std::istringstream istr("x ; return a not_eq x;");
|
||||
tokenizer.tokenize(istr, "test.c");
|
||||
Token *tok = (Token *)(tokenizer.tokens()->tokAt(5));
|
||||
ASSERT_EQUALS(false, tokenizer.duplicateDefinition(&tok, tokenizer.tokens()));
|
||||
}
|
||||
|
||||
void removestd() {
|
||||
ASSERT_EQUALS("; strcpy ( a , b ) ;", tok("; std::strcpy(a,b);"));
|
||||
ASSERT_EQUALS("; strcat ( a , b ) ;", tok("; std::strcat(a,b);"));
|
||||
|
|
Loading…
Reference in New Issue