Fixed #7046 (constexpr value used as template parameter reported as not used)
This commit is contained in:
parent
9d2258677d
commit
b54613a942
@ -773,6 +773,8 @@ void CheckUnusedVar::checkFunctionVariableUsage_iterateScopes(const Scope* const
|
|||||||
variables.clear();
|
variables.clear();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// templates
|
||||||
if (tok->isName() && tok->str().back() == '>') {
|
if (tok->isName() && tok->str().back() == '>') {
|
||||||
// TODO: This is a quick fix to handle when constants are used
|
// TODO: This is a quick fix to handle when constants are used
|
||||||
// as template parameters. Try to handle this better, perhaps
|
// as template parameters. Try to handle this better, perhaps
|
||||||
@ -823,8 +825,20 @@ void CheckUnusedVar::checkFunctionVariableUsage_iterateScopes(const Scope* const
|
|||||||
else if (Token::Match(tok->previous(), "[;{}]")) {
|
else if (Token::Match(tok->previous(), "[;{}]")) {
|
||||||
for (const Token* tok2 = tok->next(); tok2; tok2 = tok2->next()) {
|
for (const Token* tok2 = tok->next(); tok2; tok2 = tok2->next()) {
|
||||||
if (tok2->varId()) {
|
if (tok2->varId()) {
|
||||||
|
// Is this a variable declaration?
|
||||||
const Variable *var = tok2->variable();
|
const Variable *var = tok2->variable();
|
||||||
if (var && var->nameToken() == tok2) { // Declaration: Skip
|
if (!var || var->nameToken() != tok2)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
// Mark template parameters used in declaration as use..
|
||||||
|
if (tok2->strAt(-1) == ">") {
|
||||||
|
for (const Token *tok3 = tok; tok3 != tok2; tok3 = tok3->next()) {
|
||||||
|
if (tok3->varId() > 0U)
|
||||||
|
variables.use(tok3->varId(), tok3);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Skip variable declaration..
|
||||||
tok = tok2->next();
|
tok = tok2->next();
|
||||||
if (Token::Match(tok, "( %name% )")) // Simple initialization through copy ctor
|
if (Token::Match(tok, "( %name% )")) // Simple initialization through copy ctor
|
||||||
tok = tok->next();
|
tok = tok->next();
|
||||||
@ -835,7 +849,6 @@ void CheckUnusedVar::checkFunctionVariableUsage_iterateScopes(const Scope* const
|
|||||||
} else if (var->typeEndToken()->str() == ">") // Be careful with types like std::vector
|
} else if (var->typeEndToken()->str() == ">") // Be careful with types like std::vector
|
||||||
tok = tok->previous();
|
tok = tok->previous();
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
} else if (Token::Match(tok2, "[;({=]"))
|
} else if (Token::Match(tok2, "[;({=]"))
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -3884,6 +3884,12 @@ private:
|
|||||||
" f<x>();\n"
|
" f<x>();\n"
|
||||||
"}");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
|
functionVariableUsage("void f() {\n"
|
||||||
|
" constexpr std::size_t ArraySize(5);\n"
|
||||||
|
" std::array<int, ArraySize> X; X.dostuff();\n"
|
||||||
|
"}");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void localvarFuncPtr() {
|
void localvarFuncPtr() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user