File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -351,16 +351,19 @@ void CheckClass::constructors()
351351
352352 // Variables with default initializers
353353 bool hasAnyDefaultInit = false ;
354+ bool hasAnySelfInit = false ;
354355 for (Usage& usage : usageList) {
355356 const Variable& var = *usage.var ;
356357
357358 // check for C++11 initializer
358359 if (var.hasDefault ()) {
359360 usage.init = true ;
360361 hasAnyDefaultInit = true ;
362+ } else if (!hasAnySelfInit && isInitialized (usage, FunctionType::eConstructor)) {
363+ hasAnySelfInit = true ;
361364 }
362365 }
363- if (!hasAnyDefaultInit)
366+ if (!hasAnyDefaultInit && !hasAnySelfInit )
364367 continue ;
365368
366369 handleUnionMembers (usageList);
Original file line number Diff line number Diff line change @@ -769,6 +769,19 @@ class TestConstructors : public TestFixture {
769769 " int a, b;\n "
770770 " };\n " );
771771 ASSERT_EQUALS (" " , errout_str ());
772+
773+ check (" struct S { int i = 0; };\n " // #14697
774+ " struct T {\n "
775+ " S s;\n "
776+ " int j;\n "
777+ " };\n "
778+ " struct U {\n "
779+ " std::string a;\n "
780+ " int k;\n "
781+ " };\n " );
782+ ASSERT_EQUALS (" [test.cpp:4:9]: (warning) Member variable 'T::j' has no initializer. [uninitMemberVarNoCtor]\n "
783+ " [test.cpp:8:9]: (warning) Member variable 'U::k' has no initializer. [uninitMemberVarNoCtor]\n " ,
784+ errout_str ());
772785 }
773786
774787 // ticket #4290 "False Positive: style (noConstructor): The class 'foo' does not have a constructor."
You can’t perform that action at this time.
0 commit comments