Fixed #4955 (false positive: Variable 'i' is assigned a value that is never used (only used in template instantiation))
This commit is contained in:
parent
0e89620212
commit
fd67ca146d
|
@ -769,6 +769,10 @@ void CheckUnusedVar::checkFunctionVariableUsage_iterateScopes(const Scope* const
|
||||||
variables.clear();
|
variables.clear();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
if (tok->isName() && tok->str().back() == '>') {
|
||||||
|
variables.clear();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
// bailout when for_each is used
|
// bailout when for_each is used
|
||||||
if (Token::Match(tok, "%name% (") && Token::simpleMatch(tok->linkAt(1), ") {") && !Token::Match(tok, "if|for|while|switch")) {
|
if (Token::Match(tok, "%name% (") && Token::simpleMatch(tok->linkAt(1), ") {") && !Token::Match(tok, "if|for|while|switch")) {
|
||||||
|
|
|
@ -156,6 +156,7 @@ private:
|
||||||
TEST_CASE(localvarUnusedGoto); // #4447, #4558 goto
|
TEST_CASE(localvarUnusedGoto); // #4447, #4558 goto
|
||||||
TEST_CASE(localvarRangeBasedFor); // #7075
|
TEST_CASE(localvarRangeBasedFor); // #7075
|
||||||
TEST_CASE(localvarAssignInWhile);
|
TEST_CASE(localvarAssignInWhile);
|
||||||
|
TEST_CASE(localvarTemplate); // #4955 - variable is used as template parameter
|
||||||
|
|
||||||
TEST_CASE(localvarCppInitialization);
|
TEST_CASE(localvarCppInitialization);
|
||||||
TEST_CASE(localvarCpp11Initialization);
|
TEST_CASE(localvarCpp11Initialization);
|
||||||
|
@ -3875,6 +3876,15 @@ private:
|
||||||
ASSERT_EQUALS("", errout.str());
|
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() {
|
void chainedAssignment() {
|
||||||
// #5466
|
// #5466
|
||||||
functionVariableUsage("void NotUsed(double* pdD, int n) {\n"
|
functionVariableUsage("void NotUsed(double* pdD, int n) {\n"
|
||||||
|
|
Loading…
Reference in New Issue