Fixed ticket #3701 (false positive: syntax error on valid C code ( K&R function style ).
This commit is contained in:
parent
c1fc7a2218
commit
5d91ef76fe
|
@ -4879,6 +4879,9 @@ bool Tokenizer::simplifyFunctionParameters()
|
|||
bool bailOut = false;
|
||||
Token * tokparam = NULL;
|
||||
|
||||
//take count of the function name..
|
||||
std::string funcName(tok->str());
|
||||
|
||||
//floating token used to check for parameters
|
||||
Token *tok1 = tok;
|
||||
|
||||
|
@ -4894,8 +4897,24 @@ bool Tokenizer::simplifyFunctionParameters()
|
|||
//same parameters: take note of the parameter
|
||||
if (argumentNames.find(tok1->str()) != argumentNames.end())
|
||||
tokparam = tok1;
|
||||
else
|
||||
else if (tok1->str() != funcName)
|
||||
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() == ")") {
|
||||
tok1 = tok1->tokAt(2);
|
||||
|
|
|
@ -4701,18 +4701,69 @@ private:
|
|||
}
|
||||
|
||||
void vardecl19() {
|
||||
const char code[] = "void func(in, r, m)\n"
|
||||
"int in;"
|
||||
"int r,m;"
|
||||
"{\n"
|
||||
"}\n";
|
||||
{
|
||||
const char code[] = "void func(in, r, m)\n"
|
||||
"int in;"
|
||||
"int r,m;"
|
||||
"{\n"
|
||||
"}\n";
|
||||
|
||||
ASSERT_EQUALS("void func (\n"
|
||||
"int in,\n"
|
||||
"int r,\n"
|
||||
"int m)\n"
|
||||
"{\n"
|
||||
"}", tokenizeAndStringify(code));
|
||||
ASSERT_EQUALS("void func (\n"
|
||||
"int in,\n"
|
||||
"int r,\n"
|
||||
"int m)\n"
|
||||
"{\n"
|
||||
"}", 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() {
|
||||
|
|
Loading…
Reference in New Issue