From 0d82b080803630f61ce89b048de1f024420072b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Mon, 27 Aug 2012 15:48:21 +0200 Subject: [PATCH] Fixed #4040 (false positive: (error) Uninitialized variable: iter) --- lib/executionpath.cpp | 5 +++++ test/testuninitvar.cpp | 16 ++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/lib/executionpath.cpp b/lib/executionpath.cpp index 8b9f35cae..dda101cc6 100644 --- a/lib/executionpath.cpp +++ b/lib/executionpath.cpp @@ -145,6 +145,11 @@ void ExecutionPath::checkScope(const Token *tok, std::list &che return; } + if (Token::simpleMatch(tok, "union {")) { + tok = tok->next()->link(); + continue; + } + if (tok->str() == "}") return; diff --git a/test/testuninitvar.cpp b/test/testuninitvar.cpp index e56fe9527..6be444e87 100644 --- a/test/testuninitvar.cpp +++ b/test/testuninitvar.cpp @@ -558,6 +558,22 @@ private: " return Range;\n" "}\n"); ASSERT_EQUALS("", errout.str()); + + // #4040 - False positive + checkUninitVar("int f(int x) {\n" + " int iter;\n" + " {\n" + " union\n" + " {\n" + " int asInt;\n" + " double asDouble;\n" + " };\n" + "\n" + " iter = x;\n" + " }\n" + " return 1 + iter;\n" + "}"); + ASSERT_EQUALS("", errout.str()); } void uninitvar3() { // #3844