MCPcopy Create free account
hub / github.com/cppcheck-opensource/cppcheck / noConstructor16

Method noConstructor16

test/testconstructors.cpp:762–800  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

760 }
761
762 void noConstructor16() {
763 check("struct S {\n" // #14546
764 " int a = 0, b;\n"
765 "};\n");
766 ASSERT_EQUALS("[test.cpp:2:16]: (warning) Member variable 'S::b' has no initializer. [uninitMemberVarNoCtor]\n", errout_str());
767
768 check("struct S {\n"
769 " int a, b;\n"
770 "};\n");
771 ASSERT_EQUALS("", errout_str());
772
773 check("struct S {\n"
774 " explicit S(int);\n"
775 " S(const S&);\n"
776 " int i;\n"
777 "};\n"
778 "struct T {\n"
779 " S s;\n"
780 " int j{};\n"
781 "};\n");
782 ASSERT_EQUALS("", errout_str());
783
784 const char code[] = "struct S { int i = 0; };\n" // #14697
785 "struct T {\n"
786 " S s;\n"
787 " int j;\n"
788 "};\n"
789 "struct U {\n"
790 " std::string a;\n"
791 " int k;\n"
792 "};\n";
793 const Settings s = settingsBuilder(settings).cpp(Standards::CPP11).build();
794 check(code, s);
795 ASSERT_EQUALS("", errout_str());
796 check(code);
797 ASSERT_EQUALS("[test.cpp:4:9]: (warning) Member variable 'T::j' has no initializer. [uninitMemberVarNoCtor]\n"
798 "[test.cpp:8:9]: (warning) Member variable 'U::k' has no initializer. [uninitMemberVarNoCtor]\n",
799 errout_str());
800 }
801
802 // ticket #4290 "False Positive: style (noConstructor): The class 'foo' does not have a constructor."
803 // ticket #3190 "SymbolDatabase: Parse of sub class constructor fails"

Callers

nothing calls this directly

Calls 2

buildMethod · 0.80
cppMethod · 0.80

Tested by

no test coverage detected