Fixed #983 (Tokenizer::simplifyTypedef() incorrectly substitute type inside namespace)

http://sourceforge.net/apps/trac/cppcheck/ticket/983
This commit is contained in:
Slava Semushin 2009-11-20 00:02:16 +06:00
parent a5e4f957fa
commit 5369965e55
2 changed files with 20 additions and 1 deletions

View File

@ -351,7 +351,7 @@ void Tokenizer::simplifyTypedef()
int classLevel = 0; int classLevel = 0;
for (Token *tok = _tokens; tok; tok = tok->next()) for (Token *tok = _tokens; tok; tok = tok->next())
{ {
if (Token::Match(tok, "class %any%")) if (Token::Match(tok, "class|namespace %any%"))
{ {
className = tok->next()->str(); className = tok->next()->str();
classLevel = 0; classLevel = 0;

View File

@ -134,6 +134,7 @@ private:
TEST_CASE(simplifyTypedef3) TEST_CASE(simplifyTypedef3)
TEST_CASE(simplifyTypedef4) TEST_CASE(simplifyTypedef4)
TEST_CASE(simplifyTypedef5) TEST_CASE(simplifyTypedef5)
TEST_CASE(simplifyTypedef6)
TEST_CASE(reverseArraySyntax) TEST_CASE(reverseArraySyntax)
TEST_CASE(simplify_numeric_condition); TEST_CASE(simplify_numeric_condition);
@ -2079,6 +2080,24 @@ private:
ASSERT_EQUALS(expected, tok(code, false)); ASSERT_EQUALS(expected, tok(code, false));
} }
void simplifyTypedef6()
{
// ticket #983
const char code[] =
"namespace VL {\n"
" typedef float float_t ;\n"
" inline VL::float_t fast_atan2(VL::float_t y, VL::float_t x){}\n"
"}\n";
const char expected[] =
"namespace VL { "
"typedef float float_t ; "
"inline float fast_atan2 ( float y , float x ) { } "
"}";
ASSERT_EQUALS(expected, tok(code, false));
}
void reverseArraySyntax() void reverseArraySyntax()
{ {
ASSERT_EQUALS("a [ 13 ]", tok("13[a]")); ASSERT_EQUALS("a [ 13 ]", tok("13[a]"));