diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index c94ca5025..61763ccff 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -5709,16 +5709,16 @@ void Tokenizer::simplifyStdType() void Tokenizer::simplifyStaticConst() { - // This function will simplify the token list so that the qualifiers "static" + // This function will simplify the token list so that the qualifiers "extern", "static" // and "const" appear in the reverse order to what is in the array below. - const std::string qualifiers[] = {"const", "static"}; + const std::string qualifiers[] = {"const", "static", "extern"}; // Move 'const' before all other qualifiers and types and then - // move 'static' before all other qualifiers and types. + // move 'static' before all other qualifiers and types, ... for (size_t i = 0; i < sizeof(qualifiers)/sizeof(qualifiers[0]); i++) { for (Token *tok = list.front(); tok; tok = tok->next()) { - // Keep searching for an instance of "static" or "const" + // Keep searching for a qualifier if (!tok->next() || tok->next()->str() != qualifiers[i]) continue; diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 6d210afb2..29d04521a 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -8329,6 +8329,10 @@ private: "+ i13 + i14 + i15 + i16 + i17 + i18 ;\n" "}"; ASSERT_EQUALS(expected2, tokenizeAndStringify(code2, true)); + + const char code3[] = "const unsigned long extern int i;"; + const char expected3[] = "extern const unsigned long i ;"; + ASSERT_EQUALS(expected3, tokenizeAndStringify(code3, true)); } void simplifyDeprecated() {