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

@ -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
// - New to 1999 ANSI/ISO C standard
// - Not in C++ standard yet
@ -9265,6 +9265,11 @@ void Tokenizer::simplifyKeyword()
while (tok->str() == "restrict") {
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(simplifyKnownVariablesReturn); // 3500 - return
TEST_CASE(simplifyExternC);
TEST_CASE(simplifyKeyword); // #5842 - remove C99 static keyword between []
TEST_CASE(varid1);
TEST_CASE(varid2);
@ -6580,6 +6581,13 @@ private:
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"