diff --git a/lib/checkclass.cpp b/lib/checkclass.cpp index 374cee66b..37d550c2a 100644 --- a/lib/checkclass.cpp +++ b/lib/checkclass.cpp @@ -206,7 +206,7 @@ void CheckClass::constructors() std::vector usageList = createUsageList(scope); for (const Function &func : scope->functionList) { - if (!func.hasBody() || !(func.isConstructor() || func.type == Function::eOperatorEqual)) + if ((!func.hasBody() && !func.isDefault()) || !(func.isConstructor() || func.type == Function::eOperatorEqual)) continue; // Bail: If initializer list is not recognized as a variable or type then skip since parsing is incomplete @@ -694,7 +694,8 @@ bool CheckClass::isBaseClassFunc(const Token *tok, const Scope *scope) void CheckClass::initializeVarList(const Function &func, std::list &callstack, const Scope *scope, std::vector &usage) { if (!func.functionScope) - throw InternalError(nullptr, "Internal Error: Invalid syntax"); // #5702 + return; + bool initList = func.isConstructor(); const Token *ftok = func.arg->link()->next(); int level = 0; diff --git a/lib/ctu.h b/lib/ctu.h index e5cd5b755..7379fc398 100644 --- a/lib/ctu.h +++ b/lib/ctu.h @@ -60,18 +60,18 @@ namespace CTU { Location(const Tokenizer *tokenizer, const Token *tok); Location(const std::string &fileName, nonneg int lineNumber, nonneg int column) : fileName(fileName), lineNumber(lineNumber), column(column) {} std::string fileName; - nonneg int lineNumber; - nonneg int column; + nonneg int lineNumber{}; + nonneg int column{}; }; struct UnsafeUsage { UnsafeUsage() = default; UnsafeUsage(const std::string &myId, nonneg int myArgNr, const std::string &myArgumentName, const Location &location, MathLib::bigint value) : myId(myId), myArgNr(myArgNr), myArgumentName(myArgumentName), location(location), value(value) {} std::string myId; - nonneg int myArgNr; + nonneg int myArgNr{}; std::string myArgumentName; Location location; - MathLib::bigint value; + MathLib::bigint value{}; std::string toString() const; }; @@ -84,7 +84,7 @@ namespace CTU { CallBase(const Tokenizer *tokenizer, const Token *callToken); virtual ~CallBase() {} std::string callId; - int callArgNr; + int callArgNr{}; std::string callFunctionName; Location location; protected: @@ -119,7 +119,7 @@ namespace CTU { bool loadFromXml(const tinyxml2::XMLElement *xmlElement); std::string myId; - nonneg int myArgNr; + nonneg int myArgNr{}; }; std::list functionCalls; diff --git a/test/testconstructors.cpp b/test/testconstructors.cpp index 99d66e873..4173b165f 100644 --- a/test/testconstructors.cpp +++ b/test/testconstructors.cpp @@ -422,14 +422,20 @@ private: ASSERT_EQUALS("", errout.str()); } - void simple10() { // ticket #4388 - check("class Fred {\n" + void simple10() { + check("class Fred {\n" // ticket #4388 "public:\n" " Fred() = default;\n" "private:\n" " int x;\n" "};"); - ASSERT_EQUALS("", errout.str()); + ASSERT_EQUALS("[test.cpp:3]: (warning) Member variable 'Fred::x' is not initialized in the constructor.\n", errout.str()); + + check("struct S {\n" // #9391 + " 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()); } void simple11() { // ticket #4536, #6214