Fixed #3687: Don't treat catched variables as local ones.
This commit is contained in:
parent
c07044b3d3
commit
782cd5d228
|
@ -591,6 +591,8 @@ void CheckUnusedVar::checkFunctionVariableUsage_iterateScopes(const Scope* const
|
|||
if (scope->type != Scope::eClass && scope->type != Scope::eUnion && scope->type != Scope::eStruct) {
|
||||
// Find declarations
|
||||
for (std::list<Variable>::const_iterator i = scope->varlist.begin(); i != scope->varlist.end(); ++i) {
|
||||
if (i->isThrow())
|
||||
continue;
|
||||
Variables::VariableType type = Variables::none;
|
||||
if (i->isArray() && (i->nameToken()->previous()->str() == "*" || i->nameToken()->strAt(-2) == "*"))
|
||||
type = Variables::pointerArray;
|
||||
|
@ -639,7 +641,7 @@ void CheckUnusedVar::checkFunctionVariableUsage_iterateScopes(const Scope* const
|
|||
|
||||
// Check variable usage
|
||||
for (const Token *tok = scope->classDef->next(); tok && tok != scope->classEnd; tok = tok->next()) {
|
||||
if (tok->str() == "for" || tok->str() == "catch") {
|
||||
if (tok->str() == "for") {
|
||||
for (std::list<Scope*>::const_iterator i = scope->nestedList.begin(); i != scope->nestedList.end(); ++i) {
|
||||
if ((*i)->classDef == tok) { // Find associated scope
|
||||
checkFunctionVariableUsage_iterateScopes(*i, variables); // Scan child scope
|
||||
|
|
|
@ -110,6 +110,8 @@ private:
|
|||
TEST_CASE(localvarconst1);
|
||||
TEST_CASE(localvarconst2);
|
||||
|
||||
TEST_CASE(localvarthrow); // ticket #3687
|
||||
|
||||
// Don't give false positives for variables in structs/unions
|
||||
TEST_CASE(localvarStruct1);
|
||||
TEST_CASE(localvarStruct2);
|
||||
|
@ -2998,6 +3000,14 @@ private:
|
|||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void localvarthrow() { // ticket #3687
|
||||
functionVariableUsage("void foo() {\n"
|
||||
" try {}"
|
||||
" catch(Foo& bar) {}\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
// ticket #3104 - false positive when variable is read with "if (NOT var)"
|
||||
void localvarIfNOT() {
|
||||
functionVariableUsage("void f() {\n"
|
||||
|
|
Loading…
Reference in New Issue