From 90c1016c744593804eb549f48cf07a374114ee80 Mon Sep 17 00:00:00 2001 From: orbitcowboy Date: Tue, 13 May 2014 16:28:28 +0200 Subject: [PATCH] Fixed #5842: remove C99 static keyword between [] in tokenizer. --- lib/templatesimplifier.cpp | 2 +- lib/tokenize.cpp | 9 +++++++-- test/testtokenize.cpp | 8 ++++++++ 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/lib/templatesimplifier.cpp b/lib/templatesimplifier.cpp index 31f17facf..0384ad351 100644 --- a/lib/templatesimplifier.cpp +++ b/lib/templatesimplifier.cpp @@ -1241,7 +1241,7 @@ bool TemplateSimplifier::simplifyTemplateInstantiations( if (_settings->debugwarnings && errorlogger) { std::list callstack(1, tok); 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()) continue; diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index eea09b58d..e3c353c44 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -1519,7 +1519,7 @@ void Tokenizer::simplifyTypedef() void Tokenizer::simplifyMulAndParens() { if (!list.front()) - return; + return; for (Token *tok = list.front()->tokAt(3); tok; tok = tok->next()) { if (tok->isName()) { //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 // - 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(); } } diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index e66c76a6f..447982122 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -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"