From 1477087999887586713a5bd3174b65e9c1a977d8 Mon Sep 17 00:00:00 2001 From: orbitcowboy Date: Wed, 10 Apr 2024 23:14:22 +0200 Subject: [PATCH] Added test for Ticket 12514. --- test/testuninitvar.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/test/testuninitvar.cpp b/test/testuninitvar.cpp index 66faadff3fd..62ca87d0311 100644 --- a/test/testuninitvar.cpp +++ b/test/testuninitvar.cpp @@ -4350,6 +4350,28 @@ class TestUninitVar : public TestFixture { " f(i);\n" "}"); ASSERT_EQUALS("", errout_str()); + + valueFlowUninit("int f(int& i, int j, int k) {\n" // #12514 + " if (k)\n" + " i = 2;\n" + " return i + j;\n" + "}\n" + "int main() {\n" + " int i;\n" + " return f(i, 1, 0);\n" + "}"); + ASSERT_EQUALS("[test.cpp:8] -> [test.cpp:4]: (warning) Uninitialized variable: i\n", errout_str()); + + valueFlowUninit("int f(int& i, int k) {\n" + " if (k)\n" + " i = 2;\n" + " return i;\n" + "}\n" + "int main() {\n" + " int i;\n" + " return f(i, 0);\n" + "}"); + ASSERT_EQUALS("[test.cpp:8] -> [test.cpp:4]: (warning) Uninitialized variable: i\n", errout_str()); } void uninitStructMember() { // struct members