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