Move "extern" to the beginning of a declaration like "static" and "const"

This commit is contained in:
PKEuS 2015-08-29 10:57:52 +02:00
parent f89205064a
commit d5bc3285b9
2 changed files with 8 additions and 4 deletions

View File

@ -5709,16 +5709,16 @@ void Tokenizer::simplifyStdType()
void Tokenizer::simplifyStaticConst() 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. // 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 '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 (size_t i = 0; i < sizeof(qualifiers)/sizeof(qualifiers[0]); i++) {
for (Token *tok = list.front(); tok; tok = tok->next()) { 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]) if (!tok->next() || tok->next()->str() != qualifiers[i])
continue; continue;

View File

@ -8329,6 +8329,10 @@ private:
"+ i13 + i14 + i15 + i16 + i17 + i18 ;\n" "+ i13 + i14 + i15 + i16 + i17 + i18 ;\n"
"}"; "}";
ASSERT_EQUALS(expected2, tokenizeAndStringify(code2, true)); 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() { void simplifyDeprecated() {