diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index a030f5cbd..2b1f1d831 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -570,7 +570,7 @@ static void setTokenValue(Token* tok, ValueFlow::Value value, const Settings* se if (value.lifetimeKind == ValueFlow::Value::LifetimeKind::Iterator && astIsIterator(parent)) { setTokenValue(parent,value,settings); } else if (astIsPointer(tok) && astIsPointer(parent) && - (parent->isArithmeticalOp() || Token::Match(parent, "( %type%"))) { + (parent->isArithmeticalOp() || parent->isCast())) { setTokenValue(parent,value,settings); } return; diff --git a/test/testautovariables.cpp b/test/testautovariables.cpp index 16ec345a3..ad4598d94 100644 --- a/test/testautovariables.cpp +++ b/test/testautovariables.cpp @@ -2927,6 +2927,19 @@ private: " return state;\n" "}\n"); ASSERT_EQUALS("", errout.str()); + + check("struct var {\n" + " void fun();\n" + "}x;\n" + "var* T(const char*) {\n" + " return &x;\n" + "}\n" + "std::string GetTemp();\n" + "void f() {\n" + " auto a = T(GetTemp().c_str());\n" + " a->fun();\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); } void invalidLifetime() {