Fixed ticket #3721 (false positive: syntax error on valid C code ( K&R function style )).
This commit is contained in:
parent
710fefeef0
commit
be5a61b794
|
@ -5311,20 +5311,27 @@ bool Tokenizer::simplifyFunctionParameters()
|
||||||
tok1 = tok1->next();
|
tok1 = tok1->next();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bailOut) {
|
if (bailOut || !tok1) {
|
||||||
tok = tok->link();
|
tok = tok->link();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
//the two containers should hold the same size..
|
//the two containers may not hold the same size...
|
||||||
|
//in that case, the missing parameters are defined as 'int'
|
||||||
if (argumentNames.size() != argumentNames2.size()) {
|
if (argumentNames.size() != argumentNames2.size()) {
|
||||||
tok = tok->link();
|
//move back 'tok1' to the last ';'
|
||||||
//error if the second container is not empty
|
tok1 = tok1->previous();
|
||||||
if (!argumentNames2.empty()) {
|
std::map<std::string, Token *>::iterator it;
|
||||||
syntaxError(tok);
|
for (it = argumentNames.begin(); it != argumentNames.end(); ++it) {
|
||||||
return false;
|
if (argumentNames2.find(it->first) == argumentNames2.end()) {
|
||||||
|
//add the missing parameter argument declaration
|
||||||
|
tok1->insertToken(";");
|
||||||
|
tok1->insertToken(it->first);
|
||||||
|
//register the change inside argumentNames2
|
||||||
|
argumentNames2[it->first] = tok1->next();
|
||||||
|
tok1->insertToken("int");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
while (tok->str() != ")") {
|
while (tok->str() != ")") {
|
||||||
|
|
|
@ -4088,13 +4088,6 @@ private:
|
||||||
tokenizeAndStringify("void foo(int, int)\n"
|
tokenizeAndStringify("void foo(int, int)\n"
|
||||||
"{}\n");
|
"{}\n");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
//non-matching arguments after round braces
|
|
||||||
tokenizeAndStringify("void foo(x, y, z)\n"
|
|
||||||
" int x;\n"
|
|
||||||
" int y;\n"
|
|
||||||
"{}\n");
|
|
||||||
ASSERT_EQUALS("[test.cpp:1]: (error) syntax error\n", errout.str());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Simplify "((..))" into "(..)"
|
// Simplify "((..))" into "(..)"
|
||||||
|
|
Loading…
Reference in New Issue