Fix 10785: False positive: constParameter when using member pointer (#3807)

This commit is contained in:
Paul Fultz II 2022-02-07 11:45:32 -06:00 committed by GitHub
parent d528555002
commit 260d155bb6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 6 deletions

View File

@ -541,12 +541,15 @@ const Token* getParentLifetime(const Token* tok)
{
if (!tok)
return tok;
const Variable* var = tok->variable();
// TODO: Call getLifetimeVariable for deeper analysis
if (!var)
return tok;
if (var->isLocal() || var->isArgument())
return tok;
// Skipping checking for variable if its a pointer-to-member
if (!Token::simpleMatch(tok->previous(), ". *")) {
const Variable* var = tok->variable();
// TODO: Call getLifetimeVariable for deeper analysis
if (!var)
return tok;
if (var->isLocal() || var->isArgument())
return tok;
}
const Token* parent = getParentMember(tok);
if (parent != tok)
return getParentLifetime(parent);

View File

@ -2676,6 +2676,13 @@ private:
" s.g(0, PC);\n"
"};\n");
ASSERT_EQUALS("", errout.str());
// #10785
check("template <class T, class C>\n"
"struct d {\n"
" T& g(C& c, T C::*f) { return c.*f; }\n"
"};\n");
ASSERT_EQUALS("", errout.str());
}
void constParameterCallback() {