diff --git a/lib/token.cpp b/lib/token.cpp index cffbc99bd..d8b39f83c 100644 --- a/lib/token.cpp +++ b/lib/token.cpp @@ -104,6 +104,7 @@ void Token::deleteThis() _isName = _next->_isName; _isNumber = _next->_isNumber; _isBoolean = _next->_isBoolean; + _isUnused = _next->_isUnused; _varId = _next->_varId; _fileIndex = _next->_fileIndex; _linenr = _next->_linenr; diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 19ac61473..e873082ea 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -7688,6 +7688,10 @@ void Tokenizer::simplifyAttribute() if (Token::Match(tok->previous(), "%type%")) tok->previous()->isUnused(true); } + + // check if before variable name + else if (Token::Match(tok->next()->link()->next(), "%type%")) + tok->next()->link()->next()->isUnused(true); } Token::eraseTokens(tok, tok->next()->link()->next()); diff --git a/test/testunusedvar.cpp b/test/testunusedvar.cpp index 0d76fead7..3d269e540 100644 --- a/test/testunusedvar.cpp +++ b/test/testunusedvar.cpp @@ -1935,6 +1935,18 @@ private: " bool test __attribute__((unused)) = true;\n" "}\n"); ASSERT_EQUALS(std::string(""), errout.str()); + + functionVariableUsage("int foo()\n" + "{\n" + " bool __attribute__((unused)) test;\n" + "}\n"); + ASSERT_EQUALS(std::string(""), errout.str()); + + functionVariableUsage("int foo()\n" + "{\n" + " bool __attribute__((unused)) test = true;\n" + "}\n"); + ASSERT_EQUALS(std::string(""), errout.str()); } };