--author=Robert Reif <reif@earthlink.net>

Fixed #1814 (false positive: Variable hides typedef with same name)
This commit is contained in:
Daniel Marjamäki 2010-06-28 15:33:27 +02:00
parent 357e76484d
commit 46e2f1e64b
2 changed files with 21 additions and 1 deletions

View File

@ -550,7 +550,7 @@ bool Tokenizer::duplicateTypedef(Token **tokPtr, const Token *name)
// look backwards
if (Token::Match(tok->previous(), "typedef|}|>|*") ||
(Token::Match(tok->previous(), "%type%") &&
(!Token::Match(tok->previous(), "return|new|const|friend|public|private|protected") &&
(!Token::Match(tok->previous(), "return|new|const|friend|public|private|protected|throw") &&
!Token::Match(tok->tokAt(-2), "friend class"))))
{
// scan backwards for the end of the previous statement

View File

@ -204,6 +204,7 @@ private:
TEST_CASE(simplifyTypedef51);
TEST_CASE(simplifyTypedef52); // ticket #1782
TEST_CASE(simplifyTypedef53); // ticket #1801
TEST_CASE(simplifyTypedef54); // ticket #1814
TEST_CASE(simplifyTypedefFunction1);
TEST_CASE(simplifyTypedefFunction2); // ticket #1685
@ -4206,6 +4207,25 @@ private:
}
}
void simplifyTypedef54() // ticket #1814
{
const char code[] = "void foo()\n"
"{\n"
" typedef std::basic_string<char, traits_type, allocator_type> string_type;\n"
" try\n"
" {\n"
" throw string_type(\"leak\");\n"
" }\n"
" catch (const string_type&)\n"
" {\n"
" pthread_exit (0);\n"
" }\n"
"}";
checkSimplifyTypedef(code);
ASSERT_EQUALS("", errout.str());
}
void simplifyTypedefFunction1()
{
{