diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index e025d248c..f99442d53 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -502,7 +502,7 @@ void Tokenizer::simplifyTypedef() level++; } - if (Token::Match(end->next(), "%type% ;")) + if (end && end->next() && Token::Match(end->next(), "%type% ;")) { typeName = end->strAt(1); tok = end->tokAt(2); diff --git a/test/testsimplifytokens.cpp b/test/testsimplifytokens.cpp index 773ce5481..12472c49a 100644 --- a/test/testsimplifytokens.cpp +++ b/test/testsimplifytokens.cpp @@ -144,6 +144,7 @@ private: TEST_CASE(simplifyTypedef7); TEST_CASE(simplifyTypedef8); TEST_CASE(simplifyTypedef9); + TEST_CASE(simplifyTypedef10); TEST_CASE(reverseArraySyntax) TEST_CASE(simplify_numeric_condition) @@ -2372,6 +2373,33 @@ private: ASSERT_EQUALS("", errout.str()); } + void simplifyTypedef10() + { + // ticket # 1232 + const char code[] = "template struct E" + "{" + " typedef E0)?(N-1):0> v;" + " typedef typename add::val val;" + " FP_M(val);" + "};" + "template struct E " + "{" + " typedef typename D<1>::val val;" + " FP_M(val);" + "};"; + + Tokenizer tokenizer; + std::istringstream istr(code); + tokenizer.tokenize(istr, "test.cpp"); + + // Clear the error buffer.. + errout.str(""); + + tokenizer.simplifyTokenList(); + + ASSERT_EQUALS("", errout.str()); + } + void reverseArraySyntax() { ASSERT_EQUALS("a [ 13 ]", tok("13[a]"));