fix #2581 (### Internal error in Cppcheck. Please report it.)

This commit is contained in:
Robert Reif 2011-03-15 23:28:45 -04:00
parent 47531dd99c
commit f7cbc90c84
2 changed files with 34 additions and 1 deletions

View File

@ -1245,6 +1245,10 @@ void Tokenizer::simplifyTypedef()
if (tok->strAt(offset + 1) == "(")
offset++;
if (tok->tokAt(offset)->link()->strAt(-2) == "*")
functionPtr = true;
else
function = true;
funcStart = tok->tokAt(offset + 1);
funcEnd = tok->tokAt(offset)->link()->tokAt(-2);
typeName = tok->tokAt(offset)->link()->previous();
@ -1528,6 +1532,15 @@ void Tokenizer::simplifyTypedef()
if (simplifyType)
{
// can't simplify 'operator functionPtr ()' and 'functionPtr operator ... ()'
if (functionPtr && (tok2->previous()->str() == "operator" ||
tok2->next()->str() == "operator"))
{
simplifyType = false;
tok2 = tok2->next();
break;
}
// There are 2 categories of typedef substitutions:
// 1. variable declarations that preserve the variable name like
// global, local, and function parameters
@ -9472,7 +9485,7 @@ void Tokenizer::simplifyOperatorName()
par = par->next();
done = false;
}
if (Token::Match(par, "[<>+-*&/=.]") || Token::Match(par, "==|!=|<=|>="))
if (Token::Match(par, "[<>+-*&/=.!]") || Token::Match(par, "==|!=|<=|>="))
{
op += par->str();
par = par->next();

View File

@ -247,6 +247,7 @@ private:
TEST_CASE(simplifyTypedef83); // ticket #2620
TEST_CASE(simplifyTypedef84); // ticket #2630
TEST_CASE(simplifyTypedef85); // ticket #2651
TEST_CASE(simplifyTypedef86); // ticket #2581
TEST_CASE(simplifyTypedefFunction1);
TEST_CASE(simplifyTypedefFunction2); // ticket #1685
@ -4996,6 +4997,25 @@ private:
ASSERT_EQUALS("", errout.str());
}
void simplifyTypedef86() // ticket #2581
{
const char code[] = "class relational {\n"
" typedef void (safe_bool_helper::*safe_bool)();\n"
"public:\n"
" operator safe_bool() const;\n"
" safe_bool operator!() const;\n"
"};\n";
const char expected[] = "class relational { "
"; "
"public: "
"operatorsafe_bool ( ) const ; "
"safe_bool operator! ( ) const ; "
"} ;";
checkSimplifyTypedef(code);
ASSERT_EQUALS(expected, sizeof_(code));
ASSERT_EQUALS("", errout.str());
}
void simplifyTypedefFunction1()
{
{