diff --git a/lib/astutils.cpp b/lib/astutils.cpp index 1faafd4ba09..4ebbc8644da 100644 --- a/lib/astutils.cpp +++ b/lib/astutils.cpp @@ -1159,6 +1159,8 @@ bool exprDependsOnThis(const Token* expr, bool onVar, nonneg int depth) } if (expr->isOperatorKeyword() && !Token::simpleMatch(expr->next()->astParent(), ".")) return true; + if (expr->variable() && expr->variable()->isArgument() && !expr->variable()->type() && expr->variable()->scope()->function && expr->variable()->scope()->function->templateDef) + return true; } if (onVar && expr->variable()) { const Variable* var = expr->variable(); diff --git a/test/testvalueflow.cpp b/test/testvalueflow.cpp index 618e16624d8..5807e86bee2 100644 --- a/test/testvalueflow.cpp +++ b/test/testvalueflow.cpp @@ -3257,6 +3257,17 @@ class TestValueFlow : public TestFixture { " if (x) {}\n" "}\n"; ASSERT_EQUALS(true, testValueOfXKnown(code, 5U, 0)); + + code = "struct S {\n" // #13844 + " int x{};\n" + " template \n" + " void f(T t) {\n" + " x = 0;\n" + " t();\n" + " if (x == 0) {}\n" + " }\n" + "};\n"; + ASSERT_EQUALS(false, testValueOfXKnown(code, 7U, 0)); } void valueFlowAfterSwap()