Fix FP uninitMemberVar with defaulted special member functions (#4094)

* Fix #10569 FN: duplicateExpression with multiple strings compared

* Fix compiler warning

* TODO -> ASSERT

* Update testautovariables.cpp

* Improve error message

* Format

* Improve message

* Fix FP with defaulted operator=

* Fix condition
This commit is contained in:
chrchr-github 2022-05-10 13:04:45 +02:00 committed by GitHub
parent 56ac230e97
commit 52cbbb0229
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 2 deletions

View File

@ -206,8 +206,9 @@ void CheckClass::constructors()
std::vector<Usage> usageList = createUsageList(scope);
for (const Function &func : scope->functionList) {
if ((!func.hasBody() && !func.isDefault()) || !(func.isConstructor() || func.type == Function::eOperatorEqual))
continue;
if (!(func.isConstructor() && (func.hasBody() || (func.isDefault() && func.type == Function::eConstructor))) &&
!(func.type == Function::eOperatorEqual && func.hasBody()))
continue; // a defaulted constructor does not initialize primitive members
// Bail: If initializer list is not recognized as a variable or type then skip since parsing is incomplete
if (unusedTemplate && func.type == Function::eConstructor) {

View File

@ -433,6 +433,11 @@ private:
check("struct S {\n" // #9391
" S() = default;\n"
" ~S() = default;\n"
" S(const S&) = default;\n"
" S(S&&) = default;\n"
" S& operator=(const S&) = default;\n"
" S& operator=(S&&) = default;\n"
" int i;\n"
"};\n");
ASSERT_EQUALS("[test.cpp:2]: (warning) Member variable 'S::i' is not initialized in the constructor.\n", errout.str());