From ce783483d169a48e67fd93b9d89d2a1acb283394 Mon Sep 17 00:00:00 2001 From: Dmitry-Me Date: Tue, 22 Sep 2015 16:38:49 +0300 Subject: [PATCH] Continue early, reuse pattern, better names --- lib/checkunusedvar.cpp | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/lib/checkunusedvar.cpp b/lib/checkunusedvar.cpp index 931b2cf5d..c4982d5bb 100644 --- a/lib/checkunusedvar.cpp +++ b/lib/checkunusedvar.cpp @@ -1183,12 +1183,14 @@ void CheckUnusedVar::checkStructMemberUsage() } // bail out if struct is inherited - if (!structname.empty() && Token::findmatch(tok, (",|private|protected|public " + structname).c_str())) + if (!structname.empty() && Token::findmatch(tok, (",|private|protected|public " + structname).c_str())) { structname.clear(); + continue; + } // Bail out if some data is casted to struct.. - const std::string s("( struct| " + tok->next()->str() + " * ) & %name% ["); - if (Token::findmatch(tok, s.c_str())) + const std::string castPattern("( struct| " + tok->next()->str() + " * ) & %name% ["); + if (Token::findmatch(tok, castPattern.c_str())) structname.clear(); // Bail out if instance is initialized with {}.. @@ -1203,10 +1205,14 @@ void CheckUnusedVar::checkStructMemberUsage() } } + if (structname.empty()) + continue; + // bail out for extern/global struct - for (const Token *tok2 = Token::findmatch(tok, (structname + " %name%").c_str()); + const std::string definitionPattern(structname + " %name%"); + for (const Token *tok2 = Token::findmatch(tok, definitionPattern.c_str()); tok2 && tok2->next(); - tok2 = Token::findmatch(tok2->next(), (structname + " %name%").c_str())) { + tok2 = Token::findmatch(tok2->next(), definitionPattern.c_str())) { const Variable *var = tok2->next()->variable(); if (var && (var->isExtern() || (var->isGlobal() && !var->isStatic()))) {