Fixed #1846 (False positive with -s: Variable hides typedef with same name)
This commit is contained in:
parent
ab088bcec9
commit
c572e6af87
|
@ -555,7 +555,8 @@ bool Tokenizer::duplicateTypedef(Token **tokPtr, const Token *name)
|
|||
else
|
||||
{
|
||||
// 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(), "return|new|const|friend|public|private|protected|throw") &&
|
||||
!Token::Match(tok->tokAt(-2), "friend class"))))
|
||||
|
|
|
@ -207,6 +207,7 @@ private:
|
|||
TEST_CASE(simplifyTypedef54); // ticket #1814
|
||||
TEST_CASE(simplifyTypedef55);
|
||||
TEST_CASE(simplifyTypedef56); // ticket #1829
|
||||
TEST_CASE(simplifyTypedef57); // ticket #1846
|
||||
|
||||
TEST_CASE(simplifyTypedefFunction1);
|
||||
TEST_CASE(simplifyTypedefFunction2); // ticket #1685
|
||||
|
@ -4268,6 +4269,25 @@ private:
|
|||
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()
|
||||
{
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue