parent
02540c0bc0
commit
aa35462add
|
@ -7934,13 +7934,13 @@ void Tokenizer::simplifyComma()
|
||||||
for (Token *tok = list.front(); tok; tok = tok->next()) {
|
for (Token *tok = list.front(); tok; tok = tok->next()) {
|
||||||
|
|
||||||
// skip enums
|
// skip enums
|
||||||
if (Token::Match(tok, "enum class| %name%| :| %name%| {")) {
|
if (Token::Match(tok, "enum class|struct| %name%| :|{")) {
|
||||||
while (tok && tok->str() != "{")
|
Token *defStart = tok->next();
|
||||||
tok = tok->next();
|
while (Token::Match(defStart, "%name%|::|:"))
|
||||||
if (tok)
|
defStart = defStart->next();
|
||||||
tok = tok->link()->next();
|
if (defStart && defStart->str() == "{")
|
||||||
|
tok = defStart->link()->next();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!tok)
|
if (!tok)
|
||||||
syntaxError(nullptr); // invalid code like in #4195
|
syntaxError(nullptr); // invalid code like in #4195
|
||||||
|
|
||||||
|
@ -9112,6 +9112,13 @@ void Tokenizer::simplifyNamespaceStd()
|
||||||
|
|
||||||
for (const Token* tok = Token::findsimplematch(list.front(), "using namespace std ;"); tok; tok = tok->next()) {
|
for (const Token* tok = Token::findsimplematch(list.front(), "using namespace std ;"); tok; tok = tok->next()) {
|
||||||
bool insert = false;
|
bool insert = false;
|
||||||
|
if (Token::Match(tok, "enum class|struct| %name%| :|{")) { // Don't replace within enum definitions
|
||||||
|
Token *defStart = tok->next();
|
||||||
|
while (Token::Match(defStart, "%name%|::|:"))
|
||||||
|
defStart = defStart->next();
|
||||||
|
if (defStart && defStart->str() == "{")
|
||||||
|
tok = defStart->link();
|
||||||
|
}
|
||||||
if (!Token::Match(tok->previous(), ".|::")) {
|
if (!Token::Match(tok->previous(), ".|::")) {
|
||||||
if (Token::Match(tok, "%name% (") && !Token::Match(tok->linkAt(1)->next(), "%name%|{") && stdFunctions.find(tok->str()) != stdFunctions.end())
|
if (Token::Match(tok, "%name% (") && !Token::Match(tok->linkAt(1)->next(), "%name%|{") && stdFunctions.find(tok->str()) != stdFunctions.end())
|
||||||
insert = true;
|
insert = true;
|
||||||
|
|
|
@ -5568,6 +5568,33 @@ private:
|
||||||
"void search ( ) { }\n"
|
"void search ( ) { }\n"
|
||||||
"} ;";
|
"} ;";
|
||||||
ASSERT_EQUALS(expected14, tokenizeAndStringify(code14, false));
|
ASSERT_EQUALS(expected14, tokenizeAndStringify(code14, false));
|
||||||
|
|
||||||
|
// Ticket #8091
|
||||||
|
ASSERT_EQUALS("enum Anonymous0 { string } ;",
|
||||||
|
tokenizeAndStringify("using namespace std; "
|
||||||
|
"enum { string };"));
|
||||||
|
ASSERT_EQUALS("enum Type { string } ;",
|
||||||
|
tokenizeAndStringify("using namespace std; "
|
||||||
|
"enum Type { string } ;"));
|
||||||
|
ASSERT_EQUALS("enum class Type { string } ;",
|
||||||
|
tokenizeAndStringify("using namespace std; "
|
||||||
|
"enum class Type { string } ;"));
|
||||||
|
ASSERT_EQUALS("enum struct Type { string } ;",
|
||||||
|
tokenizeAndStringify("using namespace std; "
|
||||||
|
"enum struct Type { string } ;"));
|
||||||
|
ASSERT_EQUALS("enum struct Type : int { f = 0 , string } ;",
|
||||||
|
tokenizeAndStringify("using namespace std; "
|
||||||
|
"enum struct Type : int { f = 0 , string } ;"));
|
||||||
|
ASSERT_EQUALS("enum Type { a , b } ; void foo ( enum Type , std :: string ) { }",
|
||||||
|
tokenizeAndStringify("using namespace std; "
|
||||||
|
"enum Type { a , b } ; void foo ( enum Type , string) {}"));
|
||||||
|
ASSERT_EQUALS("struct T { } ; enum struct Type : int { f = 0 , string } ;",
|
||||||
|
tokenizeAndStringify("using namespace std; "
|
||||||
|
"struct T { typedef int type; } ; "
|
||||||
|
"enum struct Type : T :: type { f = 0 , string } ;"));
|
||||||
|
// Handle garbage enum code "well"
|
||||||
|
ASSERT_EQUALS("enum E : int ; void foo ( ) { std :: string s ; }",
|
||||||
|
tokenizeAndStringify("using namespace std; enum E : int ; void foo ( ) { string s ; }"));
|
||||||
}
|
}
|
||||||
|
|
||||||
void microsoftMemory() {
|
void microsoftMemory() {
|
||||||
|
|
Loading…
Reference in New Issue