Add tests for #8498, #9887 (#3680)

This commit is contained in:
chrchr-github 2022-01-07 12:34:57 +01:00 committed by GitHub
parent 8f7996211b
commit 635c09643d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 41 additions and 0 deletions

View File

@ -3533,6 +3533,18 @@ private:
" { }\n"
"};");
ASSERT_EQUALS("[test.cpp:7]: (warning) Member variable 'A::i' is not initialized in the constructor.\n", errout.str());
check("class bar {\n" // #9887
" int length;\n"
" bar() { length = 0; }\n"
"};\n"
"class foo {\n"
" int x;\n"
" foo() { Set(bar()); }\n"
" void Set(int num) { x = 1; }\n"
" void Set(bar num) { x = num.length; }\n"
"};\n");
ASSERT_EQUALS("", errout.str());
}
void uninitVarOperatorEqual() { // ticket #2415
@ -3596,6 +3608,35 @@ private:
" B() { }\n"
"};");
ASSERT_EQUALS("[test.cpp:4]: (warning) Member variable 'B::a' is not initialized in the constructor.\n", errout.str());
check("class Test {\n" // #8498
"public:\n"
" Test() {}\n"
" std::map<int, int>* pMap = nullptr;\n"
" std::string* pStr = nullptr;\n"
"};\n");
ASSERT_EQUALS("", errout.str());
check("template <typename U>\n"
"class C1 {}; \n"
"template <typename U, typename V>\n"
"class C2 {};\n"
"namespace A {\n"
" template <typename U>\n"
" class D1 {};\n"
" template <typename U, typename V>\n"
" class D2 {};\n"
"}\n"
"class Test {\n"
"public:\n"
" Test() {}\n"
" C1<int>* c1 = nullptr;\n"
" C2<int, int >* c2 = nullptr;\n"
" A::D1<int>* d1 = nullptr;\n"
" A::D2<int, int >* d2 = nullptr;\n"
" std::map<int, int>* pMap = nullptr;\n"
"};\n");
ASSERT_EQUALS("", errout.str());
}
void uninitConstVar() {