simplifyIfAddBraces: Remove restriction for jumping opening parenthesis '(' as a fix to #2873, because even without this the original test case doesn't crash anymore. Add more jumping patterns.
simplifyFunctionParameters: Add more jumping patterns and an observation related to error message for equal parameter names, help needed. Fix grammar mistake in comment.
This commit is contained in:
parent
ffb5d107be
commit
3c098839d1
|
@ -4841,8 +4841,9 @@ void Tokenizer::removeRedundantSemicolons()
|
||||||
|
|
||||||
bool Tokenizer::simplifyIfAddBraces()
|
bool Tokenizer::simplifyIfAddBraces()
|
||||||
{
|
{
|
||||||
for (Token *tok = _tokens; tok; tok = tok ? tok->next() : NULL) {
|
for (Token *tok = _tokens; tok; tok = tok->next()) {
|
||||||
if (tok->str() == "(" && !Token::Match(tok->previous(), "[;{}]")) {
|
if (tok->str() == "(" || tok->str() == "[" ||
|
||||||
|
(tok->str() == "{" && tok->previous() && tok->previous()->str() == "=")) {
|
||||||
tok = tok->link();
|
tok = tok->link();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -4861,7 +4862,7 @@ bool Tokenizer::simplifyIfAddBraces()
|
||||||
tok = tok->next()->link();
|
tok = tok->next()->link();
|
||||||
|
|
||||||
// ')' should be followed by '{'
|
// ')' should be followed by '{'
|
||||||
if (!tok || Token::simpleMatch(tok, ") {"))
|
if (Token::simpleMatch(tok, ") {"))
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4878,7 +4879,7 @@ bool Tokenizer::simplifyIfAddBraces()
|
||||||
// If there is no code after the if(), abort
|
// If there is no code after the if(), abort
|
||||||
if (!tok->next()) {
|
if (!tok->next()) {
|
||||||
// This is a syntax error and we should call syntaxError() and return false but
|
// This is a syntax error and we should call syntaxError() and return false but
|
||||||
// many tokenizer tests are written with this syntax error so just ingore it.
|
// many tokenizer tests are written with this syntax error so just ignore it.
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5523,7 +5524,11 @@ void Tokenizer::simplifyFunctionParameters()
|
||||||
|
|
||||||
if (argumentNames.find(tok->str()) != argumentNames.end()) {
|
if (argumentNames.find(tok->str()) != argumentNames.end()) {
|
||||||
// Invalid code, two arguments with the same name.
|
// Invalid code, two arguments with the same name.
|
||||||
// TODO, print error perhaps?
|
// syntaxError(tok);
|
||||||
|
// If you uncomment it, testrunner will fail:
|
||||||
|
// testclass.cpp:3910
|
||||||
|
// because of void Fred::foo5(int, int).
|
||||||
|
// how should this be handled?
|
||||||
bailOut = true;
|
bailOut = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -5537,8 +5542,6 @@ void Tokenizer::simplifyFunctionParameters()
|
||||||
|
|
||||||
if (bailOut) {
|
if (bailOut) {
|
||||||
tok = tok1->link();
|
tok = tok1->link();
|
||||||
if (!tok)
|
|
||||||
return;
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5986,12 +5986,12 @@ private:
|
||||||
tokenizeAndStringify("if()x");
|
tokenizeAndStringify("if()x");
|
||||||
ASSERT_EQUALS("[test.cpp:1]: (error) syntax error\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:1]: (error) syntax error\n", errout.str());
|
||||||
|
|
||||||
// ticket #2873
|
// ticket #2873 - the fix is not needed anymore.
|
||||||
{
|
{
|
||||||
const char code[] = "void f() { "
|
const char code[] = "void f() { "
|
||||||
"( { if(*p) (*p) = x(); } ) "
|
"(void) ( { if(*p) (*p) = x(); } ) "
|
||||||
"}";
|
"}";
|
||||||
ASSERT_EQUALS("void f ( ) { ( { if ( * p ) { ( * p ) = x ( ) ; } } ) }",
|
ASSERT_EQUALS("void f ( ) { ( void ) ( { if ( * p ) { ( * p ) = x ( ) ; } } ) }",
|
||||||
tokenizeAndStringify(code));
|
tokenizeAndStringify(code));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue