From 77e09d72a1424513b65a48e012e61218acd75be9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sun, 17 Nov 2013 12:11:18 +0100 Subject: [PATCH] Uninitialized variables: Fixed false negatives when using ({}) --- lib/checkuninitvar.cpp | 2 +- test/testuninitvar.cpp | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) 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"