Fix #10484 FP knownConditionTrueFalse with static variable and direct initialization / partial fix for #10248 (#3728)
This commit is contained in:
parent
4d9a1427b2
commit
a20465eaea
|
@ -2699,7 +2699,7 @@ static void getLHSVariablesRecursive(std::vector<const Variable*>& vars, const T
|
||||||
std::vector<const Variable*> getLHSVariables(const Token* tok)
|
std::vector<const Variable*> getLHSVariables(const Token* tok)
|
||||||
{
|
{
|
||||||
std::vector<const Variable*> result;
|
std::vector<const Variable*> result;
|
||||||
if (!Token::Match(tok, "%assign%"))
|
if (!Token::Match(tok, "%assign%|(|{"))
|
||||||
return result;
|
return result;
|
||||||
if (!tok->astOperand1())
|
if (!tok->astOperand1())
|
||||||
return result;
|
return result;
|
||||||
|
|
|
@ -3867,6 +3867,95 @@ private:
|
||||||
"}\n");
|
"}\n");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
|
// #10484
|
||||||
|
check("void f() {\n"
|
||||||
|
" static bool init = true;\n"
|
||||||
|
" if (init)\n"
|
||||||
|
" init = false;\n"
|
||||||
|
"}\n");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
|
check("void f() {\n"
|
||||||
|
" static bool init(true);\n"
|
||||||
|
" if (init)\n"
|
||||||
|
" init = false;\n"
|
||||||
|
"}\n");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
|
check("void f() {\n"
|
||||||
|
" static bool init{ true };\n"
|
||||||
|
" if (init)\n"
|
||||||
|
" init = false;\n"
|
||||||
|
"}\n");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
|
// #10248
|
||||||
|
check("void f() {\n"
|
||||||
|
" static int var(1);\n"
|
||||||
|
" if (var == 1) {}\n"
|
||||||
|
"}\n");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
|
check("void f() {\n"
|
||||||
|
" static int var{ 1 };\n"
|
||||||
|
" if (var == 1) {}\n"
|
||||||
|
"}\n");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
|
check("void Fun();\n"
|
||||||
|
"using Fn = void (*)();\n"
|
||||||
|
"void f() {\n"
|
||||||
|
" static Fn logger = nullptr;\n"
|
||||||
|
" if (logger == nullptr)\n"
|
||||||
|
" logger = Fun;\n"
|
||||||
|
"}\n");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
|
check("void Fun();\n"
|
||||||
|
"using Fn = void (*)();\n"
|
||||||
|
"void f() {\n"
|
||||||
|
" static Fn logger(nullptr);\n"
|
||||||
|
" if (logger == nullptr)\n"
|
||||||
|
" logger = Fun;\n"
|
||||||
|
"}\n");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
|
check("void Fun();\n"
|
||||||
|
"using Fn = void (*)();\n"
|
||||||
|
"void f() {\n"
|
||||||
|
" static Fn logger{ nullptr };\n"
|
||||||
|
" if (logger == nullptr)\n"
|
||||||
|
" logger = Fun;\n"
|
||||||
|
"}\n");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
|
check("void Fun();\n"
|
||||||
|
"typedef void (*Fn)();\n"
|
||||||
|
"void f() {\n"
|
||||||
|
" static Fn logger = nullptr;\n"
|
||||||
|
" if (logger == nullptr)\n"
|
||||||
|
" logger = Fun;\n"
|
||||||
|
"}\n");
|
||||||
|
TODO_ASSERT_EQUALS("", "[test.cpp:5]: (style) Condition 'logger==nullptr' is always true\n", errout.str());
|
||||||
|
|
||||||
|
check("void Fun();\n"
|
||||||
|
"typedef void (*Fn)();\n"
|
||||||
|
"void f() {\n"
|
||||||
|
" static Fn logger(nullptr);\n"
|
||||||
|
" if (logger == nullptr)\n"
|
||||||
|
" logger = Fun;\n"
|
||||||
|
"}\n");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
|
check("void Fun();\n"
|
||||||
|
"typedef void (*Fn)();\n"
|
||||||
|
"void f() {\n"
|
||||||
|
" static Fn logger{ nullptr };\n"
|
||||||
|
" if (logger == nullptr)\n"
|
||||||
|
" logger = Fun;\n"
|
||||||
|
"}\n");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
// #9256
|
// #9256
|
||||||
check("bool f() {\n"
|
check("bool f() {\n"
|
||||||
" bool b = false;\n"
|
" bool b = false;\n"
|
||||||
|
|
Loading…
Reference in New Issue