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

View File

@ -2676,6 +2676,13 @@ private:
" s.g(0, PC);\n" " s.g(0, PC);\n"
"};\n"); "};\n");
ASSERT_EQUALS("", errout.str()); 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() { void constParameterCallback() {