Fixed #4955 (false positive: Variable 'i' is assigned a value that is never used (only used in template instantiation))

This commit is contained in:
Daniel Marjamäki 2016-01-30 16:49:39 +01:00
parent 0e89620212
commit fd67ca146d
2 changed files with 14 additions and 0 deletions

View File

@ -769,6 +769,10 @@ void CheckUnusedVar::checkFunctionVariableUsage_iterateScopes(const Scope* const
variables.clear();
break;
}
if (tok->isName() && tok->str().back() == '>') {
variables.clear();
break;
}
// bailout when for_each is used
if (Token::Match(tok, "%name% (") && Token::simpleMatch(tok->linkAt(1), ") {") && !Token::Match(tok, "if|for|while|switch")) {

View File

@ -156,6 +156,7 @@ private:
TEST_CASE(localvarUnusedGoto); // #4447, #4558 goto
TEST_CASE(localvarRangeBasedFor); // #7075
TEST_CASE(localvarAssignInWhile);
TEST_CASE(localvarTemplate); // #4955 - variable is used as template parameter
TEST_CASE(localvarCppInitialization);
TEST_CASE(localvarCpp11Initialization);
@ -3875,6 +3876,15 @@ private:
ASSERT_EQUALS("", errout.str());
}
void localvarTemplate() {
functionVariableUsage("template<int A> void f() {}\n"
"void foo() {\n"
" const int x = 0;\n"
" f<x>();\n"
"}");
ASSERT_EQUALS("", errout.str());
}
void chainedAssignment() {
// #5466
functionVariableUsage("void NotUsed(double* pdD, int n) {\n"