diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 2d88be060..f1d23f0ea 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -9072,6 +9072,9 @@ void Tokenizer::simplifyKeyword() // linux kernel code at least uses "_inline" as struct member name at some // places. + const bool c99 = isC() && mSettings->standards.c >= Standards::C99; + const bool cpp11 = isCPP() && mSettings->standards.cpp >= Standards::CPP11; + for (Token *tok = list.front(); tok; tok = tok->next()) { if (keywords.find(tok->str()) != keywords.end()) { // Don't remove struct members @@ -9084,26 +9087,22 @@ void Tokenizer::simplifyKeyword() tok->deleteThis(); } + // simplify static keyword: + // void foo( int [ static 5 ] ); ==> void foo( int [ 5 ] ); + if (Token::Match(tok, "[ static %num%")) + tok->deleteNext(); - if (mSettings->standards.c >= Standards::C99) { - while (tok->str() == "restrict") { + if (c99) { + while (tok->str() == "restrict") tok->deleteThis(); - } - // simplify static keyword: - // void foo( int [ static 5 ] ); ==> void foo( int [ 5 ] ); - if (Token::Match(tok, "[ static %num%")) { - tok->deleteNext(); + if (mSettings->standards.c >= Standards::C11) { + while (tok->str() == "_Atomic") + tok->deleteThis(); } } - if (mSettings->standards.c >= Standards::C11) { - while (tok->str() == "_Atomic") { - tok->deleteThis(); - } - } - - if (isCPP() && mSettings->standards.cpp >= Standards::CPP11) { + else if (cpp11) { while (tok->str() == "constexpr") { tok->deleteThis(); } diff --git a/test/testsimplifytokens.cpp b/test/testsimplifytokens.cpp index 3354698d5..23cc39ae0 100644 --- a/test/testsimplifytokens.cpp +++ b/test/testsimplifytokens.cpp @@ -3281,6 +3281,7 @@ private: ASSERT_EQUALS("int * p ;", tok("int * restrict p;", "test.c")); ASSERT_EQUALS("int * * p ;", tok("int * restrict * p;", "test.c")); ASSERT_EQUALS("void foo ( float * a , float * b ) ;", tok("void foo(float * restrict a, float * restrict b);", "test.c")); + ASSERT_EQUALS("void foo ( int restrict ) ;", tok("void foo(int restrict);")); ASSERT_EQUALS("int * p ;", tok("typedef int * __restrict__ rint; rint p;", "test.c")); // don't remove struct members: