Skip to content

Commit 68898e2

Browse files
IOBYTERobert Reif
andauthored
fix #10335 (Type alias remains unknown with using) (#3323)
Co-authored-by: Robert Reif <reif@FX6840>
1 parent 5426ac6 commit 68898e2

2 files changed

Lines changed: 25 additions & 6 deletions

File tree

lib/tokenize.cpp

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2368,7 +2368,15 @@ bool Tokenizer::simplifyUsing()
23682368

23692369
std::string scope1 = currentScope1->fullName;
23702370
bool skip = false; // don't erase type aliases we can't parse
2371+
Token *enumOpenBrace = nullptr;
23712372
for (Token* tok1 = startToken; !skip && tok1 && tok1 != endToken; tok1 = tok1->next()) {
2373+
// skip enum body
2374+
if (tok1 && tok1 == enumOpenBrace) {
2375+
tok1 = tok1->link();
2376+
enumOpenBrace = nullptr;
2377+
continue;
2378+
}
2379+
23722380
if ((Token::Match(tok1, "{|}|namespace|class|struct|union") && tok1->strAt(-1) != "using") ||
23732381
Token::Match(tok1, "using namespace %name% ;|::")) {
23742382
setScopeInfo(tok1, &currentScope1);
@@ -2389,12 +2397,15 @@ bool Tokenizer::simplifyUsing()
23892397
continue;
23902398
}
23912399

2392-
// skip enum definitions
2393-
if (tok1->str() == "enum")
2394-
skipEnumBody(&tok1);
2395-
2396-
if (!tok1)
2397-
break;
2400+
// check for enum with body
2401+
if (tok1->str() == "enum") {
2402+
Token *defStart = tok1;
2403+
while (Token::Match(defStart, "%name%|::|:"))
2404+
defStart = defStart->next();
2405+
if (Token::simpleMatch(defStart, "{"))
2406+
enumOpenBrace = defStart;
2407+
continue;
2408+
}
23982409

23992410
// check for member function and adjust scope
24002411
if (isMemberFunction(tok1)) {

test/testsimplifyusing.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ class TestSimplifyUsing : public TestFixture {
9090
TEST_CASE(simplifyUsing10171);
9191
TEST_CASE(simplifyUsing10172);
9292
TEST_CASE(simplifyUsing10173);
93+
TEST_CASE(simplifyUsing10335);
9394
}
9495

9596
std::string tok(const char code[], bool simplify = true, Settings::PlatformType type = Settings::Native, bool debugwarnings = true) {
@@ -1304,6 +1305,13 @@ class TestSimplifyUsing : public TestFixture {
13041305
ASSERT_EQUALS(exp, tok(code, true));
13051306
}
13061307
}
1308+
1309+
void simplifyUsing10335() {
1310+
const char code[] = "using uint8_t = unsigned char;\n"
1311+
"enum E : uint8_t { E0 };";
1312+
const char exp[] = "enum E : unsigned char { E0 } ;";
1313+
ASSERT_EQUALS(exp, tok(code, false));
1314+
}
13071315
};
13081316

13091317
REGISTER_TEST(TestSimplifyUsing)

0 commit comments

Comments
 (0)