diff --git a/lib/checkuninitvar.cpp b/lib/checkuninitvar.cpp index 22aac025f..0b0a0eec4 100644 --- a/lib/checkuninitvar.cpp +++ b/lib/checkuninitvar.cpp @@ -494,11 +494,11 @@ private: if (tok.str() == "return") { - // is there assignment in the return statement? + // is there assignment or ternary operator in the return statement? bool assignment = false; for (const Token *tok2 = tok.next(); tok2 && tok2->str() != ";"; tok2 = tok2->next()) { - if (tok2->str() == "=" || tok2->str() == ">>") + if (tok2->str() == "=" || tok2->str() == ">>" || tok2->str() == "?") { assignment = true; break; diff --git a/test/testuninitvar.cpp b/test/testuninitvar.cpp index c77b4aa65..ca11ebc43 100644 --- a/test/testuninitvar.cpp +++ b/test/testuninitvar.cpp @@ -501,6 +501,13 @@ private: " return x ? 1 : y;\n" "}\n"); ASSERT_EQUALS("[test.cpp:2]: (error) Uninitialized variable: y\n", errout.str()); + + // Ticket #3106 - False positive + checkUninitVar("int f() {\n" + " int i;\n" + " return x(&i) ? i : 0;\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); }