Fix #1057 (Tokenizer: negative numbers are not tokenized correctly in switch-case)

http://sourceforge.net/apps/trac/cppcheck/ticket/1057
This commit is contained in:
Reijo Tomperi 2009-12-07 00:09:56 +02:00
parent e57d9609a7
commit f5849f9be2
2 changed files with 8 additions and 1 deletions

View File

@ -502,7 +502,7 @@ bool Tokenizer::tokenize(std::istream &code, const char FileName[])
tok->next()->deleteNext(); tok->next()->deleteNext();
} }
if (Token::Match(tok, "return - %num%") && tok->strAt(2)[0] != '-') if (Token::Match(tok, "return|case - %num%") && tok->strAt(2)[0] != '-')
{ {
tok->next()->str(std::string("-") + tok->strAt(2)); tok->next()->str(std::string("-") + tok->strAt(2));
tok->next()->deleteNext(); tok->next()->deleteNext();

View File

@ -172,6 +172,7 @@ private:
TEST_CASE(simplifyString); TEST_CASE(simplifyString);
TEST_CASE(simplifyConst); TEST_CASE(simplifyConst);
TEST_CASE(switchCase);
} }
@ -2783,6 +2784,12 @@ private:
tokenizeAndStringify("void foo(){ int * const x;}")); tokenizeAndStringify("void foo(){ int * const x;}"));
} }
void switchCase()
{
ASSERT_EQUALS("void foo ( int i ) { switch ( i ) { case -1 : break ; } }",
tokenizeAndStringify("void foo (int i) { switch(i) { case -1: break; } }"));
}
}; };
REGISTER_TEST(TestTokenizer) REGISTER_TEST(TestTokenizer)