From 2cfb2865582f9413e92a27d73acff8d3a36df691 Mon Sep 17 00:00:00 2001 From: orbitcowboy Date: Thu, 22 Jan 2015 06:53:11 +0100 Subject: [PATCH] Added test case for #5412. --- test/testuninitvar.cpp | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/test/testuninitvar.cpp b/test/testuninitvar.cpp index 67834f925..87bd6f15d 100644 --- a/test/testuninitvar.cpp +++ b/test/testuninitvar.cpp @@ -1690,7 +1690,32 @@ private: " return setvalue(x);\n" "}\n"); ASSERT_EQUALS("", errout.str()); + } + // Ticket #5412 - False negative + { + checkUninitVarB("void f(bool b)\n" + "{\n" + " double f;\n" + " if (b) { }\n" + " else {\n" + " f = 0.0;\n" + " }\n" + " printf (\"%f\",f);\n" + "}\n"); + ASSERT_EQUALS("[test.cpp:8]: (error) Uninitialized variable: f\n", errout.str()); + + // Check for potential FP + checkUninitVarB("void f(bool b)\n" + "{\n" + " double f;\n" + " if (b) { f = 1.0 }\n" + " else {\n" + " f = 0.0;\n" + " }\n" + " printf (\"%f\",f);\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); } // Ticket #2146 - False negative