Fixed #679 (False positive: Unused private function produced by exception specification)
This commit is contained in:
parent
278f1b8722
commit
e894e37131
|
@ -569,6 +569,9 @@ bool Tokenizer::tokenize(std::istream &code, const char FileName[])
|
|||
// Simplify the operator "?:"
|
||||
simplifyConditionOperator();
|
||||
|
||||
// remove exception specifications..
|
||||
removeExceptionSpecifications(_tokens);
|
||||
|
||||
// change array to pointer..
|
||||
for (Token *tok = _tokens; tok; tok = tok->next())
|
||||
{
|
||||
|
@ -4165,6 +4168,39 @@ void Tokenizer::simplifyComma()
|
|||
}
|
||||
|
||||
|
||||
void Tokenizer::removeExceptionSpecifications(Token *tok) const
|
||||
{
|
||||
while (tok)
|
||||
{
|
||||
if (tok->str() == "{")
|
||||
tok = tok->link();
|
||||
|
||||
else if (tok->str() == "}")
|
||||
break;
|
||||
|
||||
else if (Token::Match(tok, ") throw ("))
|
||||
{
|
||||
while (tok->next() && !Token::Match(tok->next(), "[;{]"))
|
||||
tok->deleteNext();
|
||||
}
|
||||
|
||||
else if (Token::Match(tok, "class %type%"))
|
||||
{
|
||||
while (tok && !Token::Match(tok, "[;{]"))
|
||||
tok = tok->next();
|
||||
if (tok && tok->str() == "{")
|
||||
{
|
||||
removeExceptionSpecifications(tok->next());
|
||||
tok = tok->link();
|
||||
}
|
||||
}
|
||||
|
||||
tok = tok ? tok->next() : 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool Tokenizer::validate() const
|
||||
{
|
||||
std::stack<const Token *> linktok;
|
||||
|
|
|
@ -304,6 +304,12 @@ private:
|
|||
*/
|
||||
std::string simplifyString(const std::string &source);
|
||||
|
||||
/**
|
||||
* Remove exception specifications. This function calls itself recursively.
|
||||
* @param tok First token in scope to cleanup
|
||||
*/
|
||||
void removeExceptionSpecifications(Token *tok) const;
|
||||
|
||||
void insertTokens(Token *dest, const Token *src, unsigned int n);
|
||||
|
||||
/**
|
||||
|
|
|
@ -155,6 +155,8 @@ private:
|
|||
TEST_CASE(testUpdateClassList);
|
||||
TEST_CASE(createLinks);
|
||||
TEST_CASE(signed1);
|
||||
|
||||
TEST_CASE(removeExceptionSpecification);
|
||||
}
|
||||
|
||||
|
||||
|
@ -2570,6 +2572,28 @@ private:
|
|||
ASSERT_EQUALS(true, tok->tokAt(9)->link() == tok->tokAt(8));
|
||||
}
|
||||
}
|
||||
|
||||
void removeExceptionSpecification()
|
||||
{
|
||||
const char code[] = "class A\n"
|
||||
"{\n"
|
||||
"private:\n"
|
||||
" void f() throw (std::runtime_error);\n"
|
||||
"};\n"
|
||||
"void A::f() throw (std::runtime_error)\n"
|
||||
"{ }";
|
||||
|
||||
const char expected[] = "class A\n"
|
||||
"{\n"
|
||||
"private:\n"
|
||||
"void f ( ) ;\n"
|
||||
"} ;\n"
|
||||
"void A :: f ( )\n"
|
||||
"{ }";
|
||||
|
||||
ASSERT_EQUALS(expected, tokenizeAndStringify(code));
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
REGISTER_TEST(TestTokenizer)
|
||||
|
|
Loading…
Reference in New Issue