Simplify enum: Fixed segmentation fault if code ends with enum type id

This commit is contained in:
Daniel Marjamäki 2010-03-07 13:01:56 +01:00
parent fa493b7fd1
commit 770d2ff835
2 changed files with 10 additions and 1 deletions

View File

@ -5756,7 +5756,7 @@ void Tokenizer::simplifyEnum()
{
// Don't replace this enum if it's preceded by "::"
}
else if (tok2->next()->isName())
else if (tok2->next() && tok2->next()->isName())
{
simplifyEnum = true;
hasClass = false;

View File

@ -205,6 +205,7 @@ private:
TEST_CASE(enum11);
TEST_CASE(enum12);
TEST_CASE(enum13);
TEST_CASE(enum14);
// remove "std::" on some standard functions
TEST_CASE(removestd);
@ -4008,6 +4009,14 @@ private:
ASSERT_EQUALS(expected, tok(code, false));
}
void enum14()
{
const char code[] = "enum ab { a };\n"
"ab";
const char expected[] = "; ab";
ASSERT_EQUALS(expected, tok(code, false));
}
void removestd()
{
ASSERT_EQUALS("; strcpy ( a , b ) ;", tok("; std::strcpy(a,b);"));