Fixed #1846 (False positive with -s: Variable hides typedef with same name)

This commit is contained in:
Robert Reif 2010-07-13 08:08:12 +02:00 committed by Daniel Marjamäki
parent ab088bcec9
commit c572e6af87
2 changed files with 22 additions and 1 deletions

View File

@ -555,7 +555,8 @@ bool Tokenizer::duplicateTypedef(Token **tokPtr, const Token *name)
else else
{ {
// look backwards // look backwards
if (Token::Match(tok->previous(), "typedef|}|>|*") || if (Token::Match(tok->previous(), "typedef|}|>") ||
(tok->previous()->str() == "*" && tok->next()->str() != "(") ||
(Token::Match(tok->previous(), "%type%") && (Token::Match(tok->previous(), "%type%") &&
(!Token::Match(tok->previous(), "return|new|const|friend|public|private|protected|throw") && (!Token::Match(tok->previous(), "return|new|const|friend|public|private|protected|throw") &&
!Token::Match(tok->tokAt(-2), "friend class")))) !Token::Match(tok->tokAt(-2), "friend class"))))

View File

@ -207,6 +207,7 @@ private:
TEST_CASE(simplifyTypedef54); // ticket #1814 TEST_CASE(simplifyTypedef54); // ticket #1814
TEST_CASE(simplifyTypedef55); TEST_CASE(simplifyTypedef55);
TEST_CASE(simplifyTypedef56); // ticket #1829 TEST_CASE(simplifyTypedef56); // ticket #1829
TEST_CASE(simplifyTypedef57); // ticket #1846
TEST_CASE(simplifyTypedefFunction1); TEST_CASE(simplifyTypedefFunction1);
TEST_CASE(simplifyTypedefFunction2); // ticket #1685 TEST_CASE(simplifyTypedefFunction2); // ticket #1685
@ -4268,6 +4269,25 @@ private:
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
} }
void simplifyTypedef57() // ticket #1846
{
const char code[] = "void foo {\n"
" typedef int A;\n"
" A a = A(1) * A(2);\n"
"};\n";
// The expected result..
const std::string expected("void foo { "
"; "
"int a ; a = int ( 1 ) * int ( 2 ) ; "
"} ;");
ASSERT_EQUALS(expected, sizeof_(code));
// Check for output..
checkSimplifyTypedef(code);
ASSERT_EQUALS("", errout.str());
}
void simplifyTypedefFunction1() void simplifyTypedefFunction1()
{ {
{ {