Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 17 additions & 6 deletions lib/tokenize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2368,7 +2368,15 @@ bool Tokenizer::simplifyUsing()

std::string scope1 = currentScope1->fullName;
bool skip = false; // don't erase type aliases we can't parse
Token *enumOpenBrace = nullptr;
for (Token* tok1 = startToken; !skip && tok1 && tok1 != endToken; tok1 = tok1->next()) {
// skip enum body
if (tok1 && tok1 == enumOpenBrace) {
tok1 = tok1->link();
enumOpenBrace = nullptr;
continue;
}

if ((Token::Match(tok1, "{|}|namespace|class|struct|union") && tok1->strAt(-1) != "using") ||
Token::Match(tok1, "using namespace %name% ;|::")) {
setScopeInfo(tok1, &currentScope1);
Expand All @@ -2389,12 +2397,15 @@ bool Tokenizer::simplifyUsing()
continue;
}

// skip enum definitions
if (tok1->str() == "enum")
skipEnumBody(&tok1);

if (!tok1)
break;
// check for enum with body
if (tok1->str() == "enum") {
Token *defStart = tok1;
while (Token::Match(defStart, "%name%|::|:"))
defStart = defStart->next();
if (Token::simpleMatch(defStart, "{"))
enumOpenBrace = defStart;
continue;
}

// check for member function and adjust scope
if (isMemberFunction(tok1)) {
Expand Down
8 changes: 8 additions & 0 deletions test/testsimplifyusing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ class TestSimplifyUsing : public TestFixture {
TEST_CASE(simplifyUsing10171);
TEST_CASE(simplifyUsing10172);
TEST_CASE(simplifyUsing10173);
TEST_CASE(simplifyUsing10335);
}

std::string tok(const char code[], bool simplify = true, Settings::PlatformType type = Settings::Native, bool debugwarnings = true) {
Expand Down Expand Up @@ -1304,6 +1305,13 @@ class TestSimplifyUsing : public TestFixture {
ASSERT_EQUALS(exp, tok(code, true));
}
}

void simplifyUsing10335() {
const char code[] = "using uint8_t = unsigned char;\n"
"enum E : uint8_t { E0 };";
const char exp[] = "enum E : unsigned char { E0 } ;";
ASSERT_EQUALS(exp, tok(code, false));
}
};

REGISTER_TEST(TestSimplifyUsing)