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:
parent
56ac230e97
commit
52cbbb0229
|
@ -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) {
|
||||
|
|
|
@ -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());
|
||||
|
|
Loading…
Reference in New Issue