Fixed #5842: remove C99 static keyword between [] in tokenizer.

This commit is contained in:
orbitcowboy 2014-05-13 16:28:28 +02:00
parent be9a566d48
commit 90c1016c74
3 changed files with 16 additions and 3 deletions

View File

@ -1241,7 +1241,7 @@ bool TemplateSimplifier::simplifyTemplateInstantiations(
if (_settings->debugwarnings && errorlogger) { if (_settings->debugwarnings && errorlogger) {
std::list<const Token *> callstack(1, tok); std::list<const Token *> callstack(1, tok);
errorlogger->reportErr(ErrorLogger::ErrorMessage(callstack, &tokenlist, Severity::debug, "debug", errorlogger->reportErr(ErrorLogger::ErrorMessage(callstack, &tokenlist, Severity::debug, "debug",
"Failed to instantiate template. The checking continues anyway.", false)); "Failed to instantiate template. The checking continues anyway.", false));
} }
if (typeForNewName.empty()) if (typeForNewName.empty())
continue; continue;

View File

@ -1519,7 +1519,7 @@ void Tokenizer::simplifyTypedef()
void Tokenizer::simplifyMulAndParens() void Tokenizer::simplifyMulAndParens()
{ {
if (!list.front()) if (!list.front())
return; return;
for (Token *tok = list.front()->tokAt(3); tok; tok = tok->next()) { for (Token *tok = list.front()->tokAt(3); tok; tok = tok->next()) {
if (tok->isName()) { if (tok->isName()) {
//fix ticket #2784 - improved by ticket #3184 //fix ticket #2784 - improved by ticket #3184
@ -9248,7 +9248,7 @@ void Tokenizer::simplifyAttribute()
} }
} }
// Remove "volatile", "inline", "register", "restrict", "override", "final" and "constexpr" // Remove "volatile", "inline", "register", "restrict", "override", "final", "static" and "constexpr"
// "restrict" keyword // "restrict" keyword
// - New to 1999 ANSI/ISO C standard // - New to 1999 ANSI/ISO C standard
// - Not in C++ standard yet // - Not in C++ standard yet
@ -9265,6 +9265,11 @@ void Tokenizer::simplifyKeyword()
while (tok->str() == "restrict") { while (tok->str() == "restrict") {
tok->deleteThis(); tok->deleteThis();
} }
// simplify static keyword:
// void foo( int [ static 5 ] ); ==> void foo( int [ 5 ] );
if (Token::Match(tok, "[ static "))
tok->deleteNext();
} }
} }

View File

@ -214,6 +214,7 @@ private:
TEST_CASE(simplifyKnownVariablesFunctionCalls); // Function calls (don't assume pass by reference) TEST_CASE(simplifyKnownVariablesFunctionCalls); // Function calls (don't assume pass by reference)
TEST_CASE(simplifyKnownVariablesReturn); // 3500 - return TEST_CASE(simplifyKnownVariablesReturn); // 3500 - return
TEST_CASE(simplifyExternC); TEST_CASE(simplifyExternC);
TEST_CASE(simplifyKeyword); // #5842 - remove C99 static keyword between []
TEST_CASE(varid1); TEST_CASE(varid1);
TEST_CASE(varid2); TEST_CASE(varid2);
@ -6580,6 +6581,13 @@ private:
ASSERT_EQUALS("if ( ! ! x ) { ; }", actual); ASSERT_EQUALS("if ( ! ! x ) { ; }", actual);
} }
void simplifyKeyword() {
const char code[] = "void f (int a [ static 5] );";
const std::string actual(tokenizeAndStringify(code, true));
ASSERT_EQUALS("void f ( int a [ 5 ] ) ;", actual);
}
/** /**
* tokenize "signed i" => "signed int i" * tokenize "signed i" => "signed int i"