Fixed ticket #3701 (false positive: syntax error on valid C code ( K&R function style ).

This commit is contained in:
Edoardo Prezioso 2012-04-03 19:48:58 +02:00
parent c1fc7a2218
commit 5d91ef76fe
2 changed files with 82 additions and 12 deletions

View File

@ -4879,6 +4879,9 @@ bool Tokenizer::simplifyFunctionParameters()
bool bailOut = false; bool bailOut = false;
Token * tokparam = NULL; Token * tokparam = NULL;
//take count of the function name..
std::string funcName(tok->str());
//floating token used to check for parameters //floating token used to check for parameters
Token *tok1 = tok; Token *tok1 = tok;
@ -4894,8 +4897,24 @@ bool Tokenizer::simplifyFunctionParameters()
//same parameters: take note of the parameter //same parameters: take note of the parameter
if (argumentNames.find(tok1->str()) != argumentNames.end()) if (argumentNames.find(tok1->str()) != argumentNames.end())
tokparam = tok1; tokparam = tok1;
else else if (tok1->str() != funcName)
argumentNames[tok1->str()] = tok1; argumentNames[tok1->str()] = tok1;
else {
if (tok1->next()->str() == ")") {
if (tok1->previous()->str() == ",") {
tok1 = tok1->tokAt(-2);
tok1->deleteNext(2);
} else {
tok1 = tok1->previous();
tok1->deleteNext();
bailOut = true;
break;
}
} else {
tok1 = tok1->tokAt(-2);
tok1->next()->deleteNext(2);
}
}
if (tok1->next()->str() == ")") { if (tok1->next()->str() == ")") {
tok1 = tok1->tokAt(2); tok1 = tok1->tokAt(2);

View File

@ -4701,6 +4701,7 @@ private:
} }
void vardecl19() { void vardecl19() {
{
const char code[] = "void func(in, r, m)\n" const char code[] = "void func(in, r, m)\n"
"int in;" "int in;"
"int r,m;" "int r,m;"
@ -4714,6 +4715,56 @@ private:
"{\n" "{\n"
"}", tokenizeAndStringify(code)); "}", tokenizeAndStringify(code));
} }
{
const char code[] = "void f(r,f)\n"
"char *r;\n"
"{\n"
"}\n";
ASSERT_EQUALS("void f (\n"
"char * r)\n"
"\n"
"{\n"
"}", tokenizeAndStringify(code));
}
{
const char code[] = "void f(f)\n"
"{\n"
"}\n";
ASSERT_EQUALS("void f ( )\n"
"{\n"
"}", tokenizeAndStringify(code));
}
{
const char code[] = "void f(f,r)\n"
"char *r;\n"
"{\n"
"}\n";
ASSERT_EQUALS("void f (\n"
"char * r)\n"
"\n"
"{\n"
"}", tokenizeAndStringify(code));
}
{
const char code[] = "void f(r,f,s)\n"
"char *r;\n"
"char *s;\n"
"{\n"
"}\n";
ASSERT_EQUALS("void f (\n"
"char * r,\n"
"\n"
"char * s)\n"
"\n"
"\n"
"{\n"
"}", tokenizeAndStringify(code));
}
}
void volatile_variables() { void volatile_variables() {
const char code[] = "volatile int a=0;\n" const char code[] = "volatile int a=0;\n"