From 52cbbb02299d269803f93b0f81bf793675b9fc0e Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Tue, 10 May 2022 13:04:45 +0200 Subject: [PATCH] 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 --- lib/checkclass.cpp | 5 +++-- test/testconstructors.cpp | 5 +++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/checkclass.cpp b/lib/checkclass.cpp index 37d550c2a..4ad7d7fc8 100644 --- a/lib/checkclass.cpp +++ b/lib/checkclass.cpp @@ -206,8 +206,9 @@ void CheckClass::constructors() std::vector 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) { diff --git a/test/testconstructors.cpp b/test/testconstructors.cpp index 4173b165f..eeec24a3a 100644 --- a/test/testconstructors.cpp +++ b/test/testconstructors.cpp @@ -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());