diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 38d8a9897..ea3367b0b 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -234,6 +234,7 @@ bool Tokenizer::duplicateTypedef(Token **tokPtr, const Token *name, const Token } else { // look backwards if (Token::Match(tok->previous(), "typedef|}|>") || + (end->str() == ";" && tok->previous()->str() == ",") || (tok->previous()->str() == "*" && tok->next()->str() != "(") || (Token::Match(tok->previous(), "%type%") && (!Token::Match(tok->previous(), "return|new|const|friend|public|private|protected|throw|extern") && diff --git a/test/testsimplifytokens.cpp b/test/testsimplifytokens.cpp index 56d2861f5..5619f4c1f 100644 --- a/test/testsimplifytokens.cpp +++ b/test/testsimplifytokens.cpp @@ -308,6 +308,8 @@ private: TEST_CASE(simplifyTypedefFunction7); TEST_CASE(simplifyTypedefFunction8); + TEST_CASE(simplifyTypedefShadow); // #4445 - shadow variable + TEST_CASE(simplifyOperator1); TEST_CASE(reverseArraySyntax) @@ -6573,6 +6575,15 @@ private: TODO_ASSERT_EQUALS("", "[test.cpp:2]: (debug) Function::addArguments found argument 'int' with varid 0.\n", errout.str()); // make sure that there is no internal error } + void simplifyTypedefShadow() { // shadow variable (#4445) + const char code[] = "typedef struct { int x; } xyz;;\n" + "void f(){\n" + " int abc, xyz;\n" // <- shadow variable + "}\n"; + ASSERT_EQUALS("struct xyz { int x ; } ; void f ( ) { int abc ; int xyz ; }", + tok(code,false)); + } + void simplifyOperator1() { // #3237 - error merging namespaces with operators const char code[] = "class c {\n"