Co-authored-by: Robert Reif <reif@FX6840>
This commit is contained in:
parent
5426ac6a22
commit
68898e2be0
|
@ -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, ¤tScope1);
|
||||
|
@ -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)) {
|
||||
|
|
|
@ -90,6 +90,7 @@ private:
|
|||
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) {
|
||||
|
@ -1304,6 +1305,13 @@ private:
|
|||
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)
|
||||
|
|
Loading…
Reference in New Issue