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:
parent
e57d9609a7
commit
f5849f9be2
|
@ -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();
|
||||||
|
|
|
@ -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)
|
||||||
|
|
Loading…
Reference in New Issue