Tokenizer: Fixed cppcheck and compiler warnings

This commit is contained in:
Robert Reif 2010-08-24 07:28:56 +02:00 committed by Daniel Marjamäki
parent d97b3bd9d9
commit d961a6ec9e
2 changed files with 16 additions and 7 deletions

View File

@ -6467,27 +6467,27 @@ void Tokenizer::simplifyEnum()
Token *enumType = 0;
Token *typeTokenStart = 0;
Token *typeTokenEnd = 0;
bool enumClass = false;
// check for C++0x enum class
if (Token::Match(tok->next(), "class|struct"))
{
tok->deleteNext();
enumClass = true;
}
// check for C++0x typed enumeration
if (Token::Match(tok->next(), "%type% :"))
if (Token::Match(tok->next(), "%type% :") || tok->next()->str() == ":")
{
int offset = 2;
if (tok->next()->str() != ":")
offset = 3;
// check for forward declaration
/** @todo start substitution check at forward declaration */
const Token *temp = tok->tokAt(3);
const Token *temp = tok->tokAt(offset);
while (!Token::Match(temp, "{|;"))
temp = temp->next();
if (temp->str() == ";")
continue;
typeTokenStart = tok->tokAt(3);
typeTokenStart = tok->tokAt(offset);
typeTokenEnd = typeTokenStart;
while (Token::Match(typeTokenEnd->next(), "signed|unsigned|char|short|int|long"))
typeTokenEnd = typeTokenEnd->next();
@ -6495,6 +6495,8 @@ void Tokenizer::simplifyEnum()
if (tok->tokAt(1)->str() == "{")
tok1 = tok->tokAt(2);
else if (tok->tokAt(1)->str() == ":")
tok1 = typeTokenEnd->tokAt(2);
else if (tok->tokAt(2)->str() == "{")
{
enumType = tok->tokAt(1);

View File

@ -5469,6 +5469,13 @@ private:
void enum15() // C++0x features
{
{
const char code[] = "enum : char { a = 99 };\n"
"char c1 = a;";
const char expected[] = "; char c1 ; c1 = 99 ;";
ASSERT_EQUALS(expected, tok(code, false));
}
{
const char code[] = "enum class Enum1 { a };\n"
"Enum1 e1 = a;";