From f7fe665b00cd70f18bef29e244cc2c25d545cd1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sun, 30 Oct 2011 18:19:09 +0100 Subject: [PATCH] Fixed #3231 (False positive: uninitialized variable '({...})') --- lib/checkuninitvar.cpp | 5 ++++- test/testuninitvar.cpp | 14 ++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/lib/checkuninitvar.cpp b/lib/checkuninitvar.cpp index e2f02b915..2db538ff9 100644 --- a/lib/checkuninitvar.cpp +++ b/lib/checkuninitvar.cpp @@ -473,7 +473,10 @@ private: if (tok.varId()) { // array variable passed as function parameter.. if (Token::Match(tok.previous(), "[(,] %var% [+-,)]")) { - use(checks, &tok); + if (Token::Match(tok.previous(), "( %var% ) =")) + ExecutionPath::bailOutVar(checks, tok.varId()); + else + use(checks, &tok); //use_array(checks, &tok); return &tok; } diff --git a/test/testuninitvar.cpp b/test/testuninitvar.cpp index d58eb238a..508cfce50 100644 --- a/test/testuninitvar.cpp +++ b/test/testuninitvar.cpp @@ -973,6 +973,20 @@ private: " }\n" "}\n"); ASSERT_EQUALS("", errout.str()); + + // #3231 - ({ switch .. }) + checkUninitVar("void f() {\n" + " int a;\n" + " ({\n" + " switch(sizeof(int)) {\n" + " case 4:\n" + " default:\n" + " (a)=0;\n" + " break;\n" + " };\n" + " })\n" + "}"); + ASSERT_EQUALS("", errout.str()); } // arrays..