From 6df0f9b3e3c8f807a05d02708c6ea735c46c1d8e Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Wed, 27 Apr 2022 12:43:21 +0200 Subject: [PATCH] Add tests for #7377, #8692, #9180 (#4053) --- test/testuninitvar.cpp | 31 +++++++++++++++++++++++++++++++ test/testvarid.cpp | 9 +++++++++ 2 files changed, 40 insertions(+) diff --git a/test/testuninitvar.cpp b/test/testuninitvar.cpp index 8d5a17308..5c5cb4305 100644 --- a/test/testuninitvar.cpp +++ b/test/testuninitvar.cpp @@ -1220,6 +1220,24 @@ private: " memset(var, 0, sizeof(var));\n" "}", "test.c"); ASSERT_EQUALS("", errout.str()); + + checkUninitVar("int f() {\n" // #8692 + " bool b = e();\n" + " int v;\n" + " if (b)\n" + " doStuff(&v);\n" + " int v2 = (b) ? v / 5 : 0;\n" + " int v3;\n" + " if (b)\n" + " v3 = 50;\n" + " int v4 = (b) ? v3 + 5 : 0;\n" + " int v5;\n" + " int v6 = v5;\n" + " doStuff(&v5);\n" + " int v7 = v5;\n" + " return v2 + v4 + v6 + v7;\n" + "}\n"); + ASSERT_EQUALS("[test.cpp:12]: (error) Uninitialized variable: v5\n", errout.str()); } @@ -4343,6 +4361,19 @@ private: " a=i;\n" "}"); ASSERT_EQUALS("[test.cpp:2]: (error) Uninitialized variable: i\n", errout.str()); + + checkUninitVar("namespace N {\n" // #7377 + " template\n" + " class C {};\n" + " using V = class C;\n" + "}\n" + "int f() {\n" + " int r = 0;\n" + " for (int x; x < 4; x++)\n" + " r += x;\n" + " return r;\n" + "}\n"); + ASSERT_EQUALS("[test.cpp:8]: (error) Uninitialized variable: x\n", errout.str()); } void uninitvar2_4494() { diff --git a/test/testvarid.cpp b/test/testvarid.cpp index 862aabeef..0b9fd844d 100644 --- a/test/testvarid.cpp +++ b/test/testvarid.cpp @@ -206,6 +206,7 @@ private: TEST_CASE(varidenum3); TEST_CASE(varidenum4); TEST_CASE(varidenum5); + TEST_CASE(varidenum6); // #9180 TEST_CASE(varidnamespace1); TEST_CASE(varidnamespace2); @@ -3344,6 +3345,14 @@ private: TODO_ASSERT_EQUALS(expected, current, tokenize(code)); } + void varidenum6() { // #9180 + const char code[] = "const int IDL1 = 13;\n" + "enum class E { IDL1 = 16, };\n"; + const char expected[] = "1: const int IDL1@1 = 13 ;\n" + "2: enum class E { IDL1 = 16 , } ;\n"; + ASSERT_EQUALS(expected, tokenize(code)); + } + void varid_classnameshaddowsvariablename() { const char code[] = "class Data;\n" "void strange_declarated(const Data& Data);\n"