From 8188578cf2b5731cd571907cd14421ab23f77824 Mon Sep 17 00:00:00 2001 From: PKEuS Date: Tue, 19 Aug 2014 11:55:00 +0200 Subject: [PATCH] SymbolDatabase: Fixed handling of nested types for function arguments Removed unnecessary loops between var->typeStartToken() and var->typeEndToken() --- lib/checkclass.cpp | 23 +---------------------- lib/checkuninitvar.cpp | 8 +------- lib/symboldatabase.cpp | 2 ++ test/testclass.cpp | 2 +- 4 files changed, 5 insertions(+), 30 deletions(-) diff --git a/lib/checkclass.cpp b/lib/checkclass.cpp index 10da1aa92..73319f8a6 100644 --- a/lib/checkclass.cpp +++ b/lib/checkclass.cpp @@ -175,14 +175,7 @@ void CheckClass::constructors() if (!var->isPointer() && !(var->type() && var->type()->needInitialization != Type::True) && (func->type == Function::eCopyConstructor || func->type == Function::eOperatorEqual)) { - bool stdtype = false; - for (const Token *type = var->typeStartToken(); type && type->isName(); type = type->next()) { - if (type->isStandardType()) { - stdtype = true; - break; - } - } - if (!stdtype) { + if (!var->typeStartToken()->isStandardType()) { if (_settings->inconclusive) inconclusive = true; else @@ -962,20 +955,6 @@ void CheckClass::checkMemset() if (derefs == 0) type = var->typeScope(); - - // TODO: The SymbolDatabase mix up variables in nested structs. - // So we must bailout right now if there are nested structs. - bool bailout = false; - for (const Token *typetok2 = var->typeStartToken(); typetok2 && typetok2 != var->typeEndToken(); typetok2 = typetok2->next()) { - if (typetok2->str() == "::") - bailout = true; - else if (typetok2->str() == "{") { - bailout = false; - break; - } - } - if (bailout) - continue; } } diff --git a/lib/checkuninitvar.cpp b/lib/checkuninitvar.cpp index 5001e573f..207668531 100644 --- a/lib/checkuninitvar.cpp +++ b/lib/checkuninitvar.cpp @@ -433,13 +433,7 @@ private: if (var2->isPointer()) checks.push_back(new UninitVar(owner, var2, symbolDatabase, library, isC)); else if (var2->typeEndToken()->str() != ">") { - bool stdtype = false; // TODO: change to isC to handle unknown types better - for (const Token* tok2 = var2->typeStartToken(); tok2 != var2->nameToken(); tok2 = tok2->next()) { - if (tok2->isStandardType()) { - stdtype = true; - break; - } - } + bool stdtype = var2->typeStartToken()->isStandardType(); // TODO: change to isC to handle unknown types better if (stdtype && (!var2->isArray() || var2->nameToken()->linkAt(1)->strAt(1) == ";")) checks.push_back(new UninitVar(owner, var2, symbolDatabase, library, isC)); } diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index 57a587bf6..99d66c1c3 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -2222,6 +2222,8 @@ void Function::addArguments(const SymbolDatabase *symbolDatabase, const Scope *s const Token *typeTok = startTok->tokAt(startTok->str() == "const" ? 1 : 0); if (typeTok->str() == "struct") typeTok = typeTok->next(); + if (Token::Match(typeTok, "%type% ::")) + typeTok = typeTok->tokAt(2); // check for argument with no name or missing varid if (!endTok) { diff --git a/test/testclass.cpp b/test/testclass.cpp index c1a0cbaa2..baa35f362 100644 --- a/test/testclass.cpp +++ b/test/testclass.cpp @@ -2204,7 +2204,7 @@ private: " n1::Fred fred;\n" " memset(&fred, 0, sizeof(fred));\n" "}"); - TODO_ASSERT_EQUALS("[test.cpp:10]: (error) Using 'memset' on class that contains a 'std::string'.\n", "", errout.str()); + ASSERT_EQUALS("[test.cpp:10]: (error) Using 'memset' on class that contains a 'std::string'.\n", errout.str()); checkNoMemset("class A {\n" " virtual ~A() { }\n"