diff --git a/lib/checkother.cpp b/lib/checkother.cpp index 908fa9699..c96478394 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -2945,7 +2945,7 @@ private: // check variable usages in rhs/index for (const Token *tok2 = tok.tokAt(2); tok2; tok2 = tok2->next()) { - if (Token::Match(tok2, ";|)|=")) + if (Token::Match(tok2, ";|)|=|?")) break; if (Token::Match(tok2, "%var% (")) break; diff --git a/test/testother.cpp b/test/testother.cpp index e2e1a56c1..dd62163c0 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -1681,6 +1681,16 @@ private: "}\n"); ASSERT_EQUALS("", errout.str()); + // ? : + checkUninitVar("static void foo(int v)\n" + "{\n" + " int x;\n" + " if (v > 0)\n" + " v = func(&x);\n" + " x = v <= 0 ? -1 : x;\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); + // while.. checkUninitVar("int f()\n" "{\n"