diff --git a/lib/checkuninitvar.cpp b/lib/checkuninitvar.cpp index d0f9703d9..2209a2625 100644 --- a/lib/checkuninitvar.cpp +++ b/lib/checkuninitvar.cpp @@ -1649,7 +1649,7 @@ bool CheckUninitVar::isVariableUsage(const Token *vartok, bool pointer, bool cpp } } - if (Token::Match(vartok->previous(), "++|--|%cop%")) { + if (Token::Match(vartok->previous(), "++|--|?|:|%cop%")) { if (cpp && vartok->previous()->str() == ">>") { // assume that variable is initialized return false; diff --git a/test/testuninitvar.cpp b/test/testuninitvar.cpp index 51e17f6fa..cd4ea6441 100644 --- a/test/testuninitvar.cpp +++ b/test/testuninitvar.cpp @@ -2152,6 +2152,13 @@ private: "}"); ASSERT_EQUALS("", errout.str()); + // = ({ .. }) + checkUninitVar2("void f() {\n" + " int x = ({ 1 + 2; });\n" + " int y = 1 + (x ? y : y);\n" + "}"); + ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: y\n", errout.str()); + // >> => initialization / usage { const char code[] = "void f() {\n"