From c86cfdaa500858cd2d8d3691c6243f4cbbea6533 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Fri, 22 May 2020 11:49:28 +0200 Subject: [PATCH] Fixed #9736 (False positive: knownArgument in assert calls) --- lib/checkother.cpp | 7 +++++++ test/testother.cpp | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/lib/checkother.cpp b/lib/checkother.cpp index edb626226..de61a0cae 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -3041,6 +3041,13 @@ void CheckOther::checkKnownArgument() tok2 = tok2->astOperand2(); if (isVariableExpression(tok2)) continue; + // ensure that function name does not contain "assert" + std::string funcname = tok->astParent()->previous()->str(); + std::transform(funcname.begin(), funcname.end(), funcname.begin(), [](int c) { + return std::tolower(c); + }); + if (funcname.find("assert") != std::string::npos) + continue; knownArgumentError(tok, tok->astParent()->previous(), &tok->values().front()); } } diff --git a/test/testother.cpp b/test/testother.cpp index 224df2585..fd9012281 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -8423,6 +8423,13 @@ private: " g(y.x);\n" "}\n"); ASSERT_EQUALS("", errout.str()); + + // allow known argument value in assert call + check("void g(int);\n" + "void f(int x) {\n" + " ASSERT((int)((x & 0x01) >> 7));\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); } void checkComparePointers() {