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());