From 1f7d9ca22c98382c5b7194bd9364f78e28cf9f1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Mon, 17 Sep 2012 19:45:42 +0200 Subject: [PATCH] Fixed #4211 (Tokenizer::simplifyVarDecl: Improved handling of >> in templates) --- lib/tokenize.cpp | 8 +++++++- test/testtokenize.cpp | 5 +++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 5ff9abd1b..1f1d1ca9e 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -5042,11 +5042,17 @@ void Tokenizer::simplifyVarDecl(bool only_k_r_fpar) if (tok3->str() == "<" && !parens) { ++indentlevel; } else if (tok3->str() == ">" && !parens) { - if (!indentlevel) { + if (indentlevel == 0) { tok2 = tok3->next(); break; } --indentlevel; + } else if (tok3->str() == ">>" && !parens) { + if (indentlevel <= 1U) { + tok2 = tok3->next(); + break; + } + indentlevel -= 2; } else if (tok3->str() == "(") { ++parens; } else if (tok3->str() == ")") { diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index f040e5bc0..0dc018b63 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -325,6 +325,7 @@ private: TEST_CASE(vardecl19); 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(vardecl_stl_1); TEST_CASE(vardecl_stl_2); TEST_CASE(vardecl_template_1); @@ -5107,6 +5108,10 @@ private: , tokenizeAndStringify(code)); } + void vardecl22() { // #4211 - segmentation fault + tokenizeAndStringify("A> >* p = 0;"); + } + void volatile_variables() { const char code[] = "volatile int a=0;\n" "volatile int b=0;\n"