diff --git a/src/tokenize.cpp b/src/tokenize.cpp index 9a59fb74d..8b404e903 100644 --- a/src/tokenize.cpp +++ b/src/tokenize.cpp @@ -2279,6 +2279,14 @@ void Tokenizer::simplifyFunctionParameters() break; } + if (argumentNames.find(tok->str()) != argumentNames.end()) + { + // Invalid code, two arguments with the same name. + // TODO, print error perhaps? + bailOut = true; + break; + } + argumentNames[tok->str()] = tok; if (tok->next()->str() == ")") { diff --git a/test/testsimplifytokens.cpp b/test/testsimplifytokens.cpp index 5e04b8857..f10458a3a 100644 --- a/test/testsimplifytokens.cpp +++ b/test/testsimplifytokens.cpp @@ -111,6 +111,9 @@ private: // Simplify nested strcat() calls TEST_CASE(strcat1); + + // Syntax error + TEST_CASE(argumentsWithSameName) } std::string tok(const char code[]) @@ -1363,6 +1366,16 @@ private: ASSERT_EQUALS(expect, tok(code)); } + + void argumentsWithSameName() + { + // This code has syntax error, two variables can not have the same name + const char code[] = "void foo(x, x)\n" + " int x;\n" + " int x;\n" + "{}\n"; + ASSERT_EQUALS("void foo ( x , x ) int x ; int x ; { }", tok(code)); + } }; REGISTER_TEST(TestSimplifyTokens)