From 0d530711f6ae137052b0762410021cf3fe7634cb Mon Sep 17 00:00:00 2001 From: Robert Reif Date: Mon, 30 Aug 2010 07:25:17 +0200 Subject: [PATCH] Fixed #1988 (segmentation fault of cppcheck with wrong syntax of -std=c++0x) --- lib/tokenize.cpp | 6 ++++++ test/testsimplifytokens.cpp | 8 ++++++++ 2 files changed, 14 insertions(+) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index c873bf258..3fca39e8f 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -6646,6 +6646,12 @@ void Tokenizer::simplifyEnum() typeTokenEnd = typeTokenStart; while (Token::Match(typeTokenEnd->next(), "signed|unsigned|char|short|int|long")) typeTokenEnd = typeTokenEnd->next(); + + if (!Token::Match(typeTokenEnd->next(), "{|;")) + { + syntaxError(typeTokenEnd->next()); + return; + } } if (tok->tokAt(1)->str() == "{") diff --git a/test/testsimplifytokens.cpp b/test/testsimplifytokens.cpp index d65dd32fc..4e69a895d 100644 --- a/test/testsimplifytokens.cpp +++ b/test/testsimplifytokens.cpp @@ -250,6 +250,7 @@ private: TEST_CASE(enum13); TEST_CASE(enum14); TEST_CASE(enum15); + TEST_CASE(enum16); // ticket #1988 // remove "std::" on some standard functions TEST_CASE(removestd); @@ -5513,6 +5514,13 @@ private: } } + void enum16() // ticket #1988 + { + const char code[] = "enum D : auto * { FF = 0 };"; + checkSimplifyEnum(code); + ASSERT_EQUALS("[test.cpp:1]: (error) syntax error\n", errout.str()); + } + void removestd() { ASSERT_EQUALS("; strcpy ( a , b ) ;", tok("; std::strcpy(a,b);"));