diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index ac5c44d57..e9c758429 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -8531,7 +8531,7 @@ void Tokenizer::simplifyEnum() simplify = true; hasClass = true; } - else if (inScope && !exitThisScope && (tok2->str() == enumType->str() || (tok2->str() == "enum" && tok2->next()->str() == enumType->str()))) + else if (inScope && !exitThisScope && (tok2->str() == enumType->str() || (tok2->str() == "enum" && tok2->next() && tok2->next()->str() == enumType->str()))) { if (Token::simpleMatch(tok2->previous(), "::")) { diff --git a/test/testsimplifytokens.cpp b/test/testsimplifytokens.cpp index 28810954c..0fff9f6c9 100644 --- a/test/testsimplifytokens.cpp +++ b/test/testsimplifytokens.cpp @@ -313,6 +313,7 @@ private: TEST_CASE(enum23); // ticket #2804 TEST_CASE(enum24); // ticket #2828 TEST_CASE(enum25); // ticket #2966 + TEST_CASE(enum26); // ticket #2975 (segmentation fault) // remove "std::" on some standard functions TEST_CASE(removestd); @@ -6657,6 +6658,13 @@ private: ASSERT_EQUALS("[test.cpp:1]: (error) syntax error\n", errout.str()); } + void enum26() // ticket #2978 (segmentation fault) + { + const char code[] = "enum E {} e enum\n"; + tok(code, false); + ASSERT_EQUALS("", errout.str()); + } + void removestd() { ASSERT_EQUALS("; strcpy ( a , b ) ;", tok("; std::strcpy(a,b);"));