diff --git a/checkclass.cpp b/checkclass.cpp index 41a3bfaf5..6c1030a7f 100644 --- a/checkclass.cpp +++ b/checkclass.cpp @@ -322,6 +322,7 @@ void CheckClass::constructors() const char *className[2]; className[0] = tok1->strAt( 1 ); className[1] = 0; + const Token *classNameToken = tok1->tokAt( 1 ); // TODO: handling of private constructors should be improved. bool hasPrivateConstructor = false; @@ -351,7 +352,7 @@ void CheckClass::constructors() isPrivate = false; // Is there a private constructor? - else if ( isPrivate && Token::Match(tok, "%var1% (", 0, className) ) + else if ( isPrivate && Token::Match(tok, "%varid% (", classNameToken->varId()) ) { hasPrivateConstructor = true; break; @@ -369,9 +370,9 @@ void CheckClass::constructors() } // Are there a class constructor? - const Token *constructor_token = Token::findmatch( tok1, "%any% %var1% (", className ); + const Token *constructor_token = Token::findmatch( tok1, "%any% %varid% (", classNameToken->varId() ); while ( Token::Match( constructor_token, "~" ) ) - constructor_token = Token::findmatch( constructor_token->next(), "%any% %var1% (", className ); + constructor_token = Token::findmatch( constructor_token->next(), "%any% %varid% (", classNameToken->varId() ); // There are no constructor. if ( ! constructor_token ) @@ -385,7 +386,7 @@ void CheckClass::constructors() { std::ostringstream ostr; ostr << _tokenizer->fileLine(tok1); - ostr << " The class '" << className[0] << "' has no constructor"; + ostr << " The class '" << classNameToken->str() << "' has no constructor"; _errorLogger->reportErr(ostr.str()); } // Delete the varlist.. diff --git a/token.cpp b/token.cpp index 956c956d7..719f1ac4d 100644 --- a/token.cpp +++ b/token.cpp @@ -359,6 +359,16 @@ const Token *Token::findmatch(const Token *tok, const char pattern[], const char return 0; } +const Token *Token::findmatch(const Token *tok, const char pattern[], unsigned int varId ) +{ + for ( ; tok; tok = tok->next()) + { + if ( Token::Match(tok, pattern, varId) ) + return tok; + } + return 0; +} + unsigned int Token::varId() const { return _varId; diff --git a/token.h b/token.h index a7b25b641..5ac492b26 100644 --- a/token.h +++ b/token.h @@ -112,6 +112,7 @@ public: bool isBoolean() const; bool isStandardType() const; static const Token *findmatch(const Token *tok, const char pattern[], const char *varname1[]=0); + static const Token *findmatch(const Token *tok, const char pattern[], unsigned int varId ); /** * Needle is build from multiple alternatives. If one of