From 260d155bb6efa64d6648c123aa3d560216c187b1 Mon Sep 17 00:00:00 2001 From: Paul Fultz II Date: Mon, 7 Feb 2022 11:45:32 -0600 Subject: [PATCH] Fix 10785: False positive: constParameter when using member pointer (#3807) --- lib/astutils.cpp | 15 +++++++++------ test/testother.cpp | 7 +++++++ 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/lib/astutils.cpp b/lib/astutils.cpp index 9566a5fbf..98fe9f2b0 100644 --- a/lib/astutils.cpp +++ b/lib/astutils.cpp @@ -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); diff --git a/test/testother.cpp b/test/testother.cpp index dcc39cb5f..129afd1a5 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -2676,6 +2676,13 @@ private: " s.g(0, PC);\n" "};\n"); ASSERT_EQUALS("", errout.str()); + + // #10785 + check("template \n" + "struct d {\n" + " T& g(C& c, T C::*f) { return c.*f; }\n" + "};\n"); + ASSERT_EQUALS("", errout.str()); } void constParameterCallback() {