diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 9b2aec1d5..6c921465a 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -4995,6 +4995,10 @@ void Tokenizer::simplifyVarDecl(bool only_k_r_fpar) //skip combinations of templates and namespaces while (Token::Match(tok2, "%type% <") || Token::Match(tok2, "%type% ::")) { + if (tok2->next()->str() == "<" && !TemplateSimplifier::templateParameters(tok2->next())) { + tok2 = NULL; + break; + } typelen += 2; tok2 = tok2->tokAt(2); if (tok2 && tok2->previous()->str() == "::") diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 9923b7514..d209e5eba 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -334,6 +334,7 @@ private: TEST_CASE(vardecl20); // #3700 - register const int H = 0; TEST_CASE(vardecl21); // #4042 - a::b const *p = 0; TEST_CASE(vardecl22); // #4211 - segmentation fault + TEST_CASE(vardecl23); // #4276 - segmentation fault TEST_CASE(vardecl_stl_1); TEST_CASE(vardecl_stl_2); TEST_CASE(vardecl_template_1); @@ -5252,6 +5253,10 @@ private: tokenizeAndStringify("A> >* p = 0;"); } + void vardecl23() { // #4276 - segmentation fault + tokenizeAndStringify("class a { protected : template < class int x = 1 ; public : int f ( ) ; }"); + } + void volatile_variables() { const char code[] = "volatile int a=0;\n" "volatile int b=0;\n"