Skip to content

Commit 2733865

Browse files
committed
Fix the FP introduced in this PR
1 parent 4f40e4f commit 2733865

2 files changed

Lines changed: 13 additions & 0 deletions

File tree

‎lib/checkother.cpp‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3351,6 +3351,10 @@ bool CheckOtherImpl::testIfNonZeroExpressionIsPositive(const Token *tok, const V
33513351
return false;
33523352
}
33533353

3354+
if (const Variable* var = nonZeroExpr->variable())
3355+
if (var->typeStartToken()->isTemplateArg())
3356+
return false;
3357+
33543358
const ValueType* vt = nonZeroExpr->valueType();
33553359
return vt && (vt->pointer || vt->sign == ValueType::UNSIGNED);
33563360
}

‎test/testother.cpp‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9641,6 +9641,15 @@ class TestOther : public TestFixture {
96419641
"}\n");
96429642
ASSERT_EQUALS("", errout_str());
96439643

9644+
// template parameter type is deduced as unsigned from the call
9645+
check("template<class T> bool pos(T x) { return x >= 0; }\n"
9646+
"void use() { unsigned u = 3; pos(u); }\n");
9647+
ASSERT_EQUALS("", errout_str());
9648+
9649+
check("template<class T> bool neg(T x) { return 0 <= x; }\n"
9650+
"void use() { unsigned u = 3; neg(u); }\n");
9651+
ASSERT_EQUALS("", errout_str());
9652+
96449653
// #13734
96459654
check("void f() {\n"
96469655
" uint8_t a[N + 1];\n"

0 commit comments

Comments
 (0)