Fix #870 (The CheckClass::getVarList method detects 'const' as a variable name.)

http://sourceforge.net/apps/trac/cppcheck/ticket/870
This commit is contained in:
Reijo Tomperi 2009-10-29 21:54:51 +02:00
parent 504ae8e22d
commit 4a61bd0432
2 changed files with 7 additions and 1 deletions

View File

@ -2421,6 +2421,9 @@ void Tokenizer::simplifyCasts()
if (tok->isName() && tok->str() != "return")
break;
if (Token::simpleMatch(tok->previous(), "operator"))
break;
// Remove cast..
Token::eraseTokens(tok, tok->next()->link()->next());
@ -3475,7 +3478,8 @@ bool Tokenizer::simplifyCalculations()
// Remove parantheses around variable..
// keep parantheses here: dynamic_cast<Fred *>(p);
if (!tok->isName() && tok->str() != ">" && Token::Match(tok->next(), "( %var% ) [;),+-*/><]]"))
// keep parantheses here: A operator * (int);
if (!tok->isName() && tok->str() != ">" && Token::Match(tok->next(), "( %var% ) [;),+-*/><]]") && !Token::simpleMatch(tok->previous(), "operator"))
{
tok->deleteNext();
tok = tok->next();

View File

@ -176,6 +176,8 @@ private:
ASSERT_EQUALS("if ( * a )", tok("if ((char)*a)"));
ASSERT_EQUALS("if ( & a )", tok("if ((int)&a)"));
ASSERT_EQUALS("if ( * a )", tok("if ((unsigned int)(unsigned char)*a)"));
ASSERT_EQUALS("class A { A operator * ( int ) ; } ;", tok("class A { A operator *(int); };"));
ASSERT_EQUALS("class A { A operator * ( int ) const ; } ;", tok("class A { A operator *(int) const; };"));
}