This commit is contained in:
chrchr-github 2022-04-27 12:43:21 +02:00 committed by GitHub
parent 6796f9daa2
commit 6df0f9b3e3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 40 additions and 0 deletions

View File

@ -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<typename T>\n"
" class C {};\n"
" using V = class C<void>;\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() {

View File

@ -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"