Skip to content

Commit 4b08731

Browse files
Fix #13844 FP knownConditionTrueFalse when passing callable to template function (#8832)
1 parent a46d2fb commit 4b08731

2 files changed

Lines changed: 13 additions & 0 deletions

File tree

‎lib/astutils.cpp‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1159,6 +1159,8 @@ bool exprDependsOnThis(const Token* expr, bool onVar, nonneg int depth)
11591159
}
11601160
if (expr->isOperatorKeyword() && !Token::simpleMatch(expr->next()->astParent(), "."))
11611161
return true;
1162+
if (expr->variable() && expr->variable()->isArgument() && !expr->variable()->type() && expr->variable()->scope()->function && expr->variable()->scope()->function->templateDef)
1163+
return true;
11621164
}
11631165
if (onVar && expr->variable()) {
11641166
const Variable* var = expr->variable();

‎test/testvalueflow.cpp‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3257,6 +3257,17 @@ class TestValueFlow : public TestFixture {
32573257
" if (x) {}\n"
32583258
"}\n";
32593259
ASSERT_EQUALS(true, testValueOfXKnown(code, 5U, 0));
3260+
3261+
code = "struct S {\n" // #13844
3262+
" int x{};\n"
3263+
" template <typename T>\n"
3264+
" void f(T t) {\n"
3265+
" x = 0;\n"
3266+
" t();\n"
3267+
" if (x == 0) {}\n"
3268+
" }\n"
3269+
"};\n";
3270+
ASSERT_EQUALS(false, testValueOfXKnown(code, 7U, 0));
32603271
}
32613272

32623273
void valueFlowAfterSwap()

0 commit comments

Comments
 (0)