From 4a61bd04328d20d58f0ed74a316372ea18307952 Mon Sep 17 00:00:00 2001 From: Reijo Tomperi Date: Thu, 29 Oct 2009 21:54:51 +0200 Subject: [PATCH] Fix #870 (The CheckClass::getVarList method detects 'const' as a variable name.) http://sourceforge.net/apps/trac/cppcheck/ticket/870 --- lib/tokenize.cpp | 6 +++++- test/testsimplifytokens.cpp | 2 ++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index b57b97012..ab42fc04c 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -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(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(); diff --git a/test/testsimplifytokens.cpp b/test/testsimplifytokens.cpp index 90b0b9d26..9d46ac121 100644 --- a/test/testsimplifytokens.cpp +++ b/test/testsimplifytokens.cpp @@ -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; };")); }